﻿var file_type = "";
var word_file_type = "";
function sleep(milliseconds) {
    var start = new Date().getTime();
    for (var i = 0; i < 1e7; i++) {
        if ((new Date().getTime() - start) > milliseconds) {
            break;
        }
    }
}
function readURL2(input) {

    if (input.files && input.files[0]) {
        var reader = new FileReader();

        reader.onload = function (e) {

            var split = e.target.result.toString().split("/");
            file_type = split[0];
            if (split[0] == "data:image") {
                document.getElementById("audio_upload").style.display = "none";
                document.getElementById("img_upload").style.display = "inline-block";
                document.getElementById("upload_name").style.display = "block";
                $('#img_upload').attr('src', e.target.result);
            }
            else {
                if (split[0] == "data:audio") {
                    document.getElementById("audio_upload").style.display = "inline-block";
                    document.getElementById("img_upload").style.display = "none";
                    $('#audio_upload').attr('src', e.target.result);
                    document.getElementById("upload_name").style.display = "block";
                }
                else {
                    document.getElementById("audio_upload").style.display = "none";
                    document.getElementById("img_upload").style.display = "none";
                    document.getElementById("upload_name").style.display = "none";
                }
            }
        }

        reader.readAsDataURL(input.files[0]);
    }
}
//function readURL3(input) {

//    if (input.files && input.files[0]) {
//        var reader = new FileReader();

//        reader.onload = function (e) {

//            var split = e.target.result.toString().split("/");
//            word_file_type = split[0];
//            if (split[0] == "data:audio") {
//                document.getElementById("snd_word").style.display = "inline-block";
//                $('#snd_word').attr('src', e.target.result);
//            }
//            else {
//                document.getElementById("snd_word").style.display = "none";
//                alert("tập tin không hợp lệ");
//                document.getElementById("word-sound").value = "";
//            }
//        }
//    }
//    reader.readAsDataURL(input.files[0]);
//}
function openmedia(evt, medianame) {
    var i, x, tablinks;
    x = document.getElementsByClassName("media-content");
    for (i = 0; i < x.length; i++) {
        x[i].style.display = "none";
    }
    tablinks = document.getElementsByClassName("media-link");
    for (i = 0; i < x.length; i++) {
        tablinks[i].className = tablinks[i].className.replace(" w3-bottombar", " deactive");
    }
    document.getElementById(medianame).style.display = "block";
    evt.currentTarget.className = evt.currentTarget.className.replace(" deactive", " w3-bottombar");
}
function talk_result() {
    $(this).parent().children('.themvidu').animate({ height: 'toggle' }, 'fast')
};
function readURL(input, id) {

    if (input.files && input.files[0]) {
        var reader = new FileReader();

        reader.onload = function (e) {

            var split = e.target.result.toString().split("/");
            file_type = split[0];

            if (split[0] == "data:audio") {
                $('#Read_audio_' + id).attr('src', e.target.result);
            }
            else {
                alert("Tập tin không hợp lệ")
            }
        }

        reader.readAsDataURL(input.files[0]);
    }
}
$(document).ready(function () {
    $(document).ready(function () {
        $('[data-toggle="tooltip"]').tooltip();
    });
    $(".themdoithoai-btn").click(function () {
        $(this).parent().children('.themvidu').animate({ height: 'toggle' }, 'fast')
    });
    $(".grammar-name").click(function () {
        if ($(this).parent().hasClass("selected")) {
            $(this).children(".muiten").removeClass("fa-rotate-180");
            $(this).parent().children(".lesson-child-content").animate({ height: 'toggle' }, "fast");
            $(this).parent().removeClass("selected");
        }
            //else if ($(this).parent().parent().children().hasClass("selected")) {
            //    $(this).parent().parent().children(".selected").children(".grammar-name").children(".muiten").removeClass("fa-rotate-180");
            //    $(this).parent().parent().children(".selected").children(".lesson-child-content").animate({ height: 'toggle' }, "fast");
            //    $(this).parent().parent().children(".selected").removeClass("selected");
            //    $(this).parent().addClass("selected");
            //    $(this).children(".muiten").addClass("fa-rotate-180");
            //    $(this).parent().children(".lesson-child-content").animate({ height: 'toggle' }, "fast");
            //}
        else {
            $(this).parent().addClass("selected");
            $(this).children(".muiten").addClass("fa-rotate-180");
            $(this).parent().children(".lesson-child-content").animate({ height: 'toggle' }, "fast");
        }
    });
    $(".read-name").click(function () {
        if ($(this).parent().hasClass("selected")) {
            $(this).children(".muiten").removeClass("fa-rotate-180");
            $(this).parent().children(".lesson-child-content").animate({ height: 'toggle' }, "fast");
            $(this).parent().removeClass("selected");
        }
            //else if ($(this).parent().parent().children().hasClass("selected")) {
            //    $(this).parent().parent().children(".selected").children(".grammar-name").children(".muiten").removeClass("fa-rotate-180");
            //    $(this).parent().parent().children(".selected").children(".lesson-child-content").animate({ height: 'toggle' }, "fast");
            //    $(this).parent().parent().children(".selected").removeClass("selected");
            //    $(this).parent().addClass("selected");
            //    $(this).children(".muiten").addClass("fa-rotate-180");
            //    $(this).parent().children(".lesson-child-content").animate({ height: 'toggle' }, "fast");
            //}
        else {
            $(this).parent().addClass("selected");
            $(this).children(".muiten").addClass("fa-rotate-180");
            $(this).parent().children(".lesson-child-content").animate({ height: 'toggle' }, "fast");
        }
    });
    $(".talk-name").click(function () {
        if ($(this).parent().hasClass("selected")) {
            $(this).children(".muiten").removeClass("fa-rotate-180");
            $(this).parent().children(".lesson-child-content").animate({ height: 'toggle' }, "fast");
            $(this).parent().removeClass("selected");
        }
            //else if ($(this).parent().parent().children().hasClass("selected")) {
            //    $(this).parent().parent().children(".selected").children(".grammar-name").children(".muiten").removeClass("fa-rotate-180");
            //    $(this).parent().parent().children(".selected").children(".lesson-child-content").animate({ height: 'toggle' }, "fast");
            //    $(this).parent().parent().children(".selected").removeClass("selected");
            //    $(this).parent().addClass("selected");
            //    $(this).children(".muiten").addClass("fa-rotate-180");
            //    $(this).parent().children(".lesson-child-content").animate({ height: 'toggle' }, "fast");
            //}
        else {
            $(this).parent().addClass("selected");
            $(this).children(".muiten").addClass("fa-rotate-180");
            $(this).parent().children(".lesson-child-content").animate({ height: 'toggle' }, "fast");
        }
    });
    $("#btn_upload_file").click(function () {
        var file = document.getElementById("fileUpload").value;
        var name = document.getElementById("txt_file_name").value;
        if (file != "") {
            if (file_type != "data:image" && file_type != "data:audio") {
                alert("Tập tin này không thuộc hình ảnh hoặc âm thanh");
            }
            else {
                if (name != "") {
                    var file_data = document.getElementById('fileUpload').files[0];
                    if (file_data == null) return; // chưa chọn file
                    var form_data = new FormData();
                    form_data.append("fileUpload", file_data);
                    $.ajax({
                        url: '../ajax/asp/certificate/upload.aspx?type=' + file_type + "&name=" + name.trim(),
                        data: form_data,
                        processData: false,
                        contentType: false,
                        type: 'POST',
                        success: function (data) {
                            //$("#divTreeView").html(data);
                        }
                    });
                    document.getElementById("fileUpload").value = "";
                    document.getElementById("txt_file_name").value = "";
                    document.getElementById("upload_name").style.display = "none";
                    document.getElementById("audio_upload").style.display = "none";
                    document.getElementById("img_upload").style.display = "none";
                    document.getElementById("upload-media-modal").style.display = "none";

                    if (file_type == "data:image") {
                        document.getElementById("pic_area").innerHTML = '<div id="loading"><div id="loading-center-absolute"><div class="object w3-text-teal" id="object_four"></div><div class="object w3-text-teal" id="object_three"></div><div class="object w3-text-teal" id="object_two"></div><div class="object w3-text-teal" id="object_one"></div></div></div>';

                        var xhttp;
                        xhttp = new XMLHttpRequest();
                        xhttp.onreadystatechange = function () {
                            if (xhttp.readyState == 4 && xhttp.status == 200) {
                                document.getElementById("pic_area").innerHTML = xhttp.responseText;
                                $(".media-item").click(function () {
                                    var link = this.getElementsByClassName("media-link")[0].innerHTML;
                                    document.getElementById("library_link").value = link;
                                });
                                $(document).ready(function () {
                                    $('[data-toggle="popover"]').popover();
                                });
                                var max = document.getElementById("load_more_img").getElementsByClassName("total_media")[0].innerHTML;
                                max++; document.getElementById("load_more_img").getElementsByClassName("total_media")[0].innerHTML = max;
                                max = document.getElementById("load_more_img").getElementsByClassName("total_media")[0].innerHTML;
                                var count = $("#pic_area .media-item").length;
                                if (count < max)
                                    document.getElementById("btn_load_more_img").style.display = "inline-block";
                            }
                        };
                        sleep(5000);
                        xhttp.open("GET", "../ajax/asp/certificate/load_img.aspx", true);
                        xhttp.send();
                    }
                    else {
                        document.getElementById("audio_area").innerHTML = '<div id="loading"><div id="loading-center-absolute"><div class="object w3-text-teal" id="object_four"></div><div class="object w3-text-teal" id="object_three"></div><div class="object w3-text-teal" id="object_two"></div><div class="object w3-text-teal" id="object_one"></div></div></div>';
                        var xhttp;
                        xhttp = new XMLHttpRequest();
                        xhttp.onreadystatechange = function () {
                            if (xhttp.readyState == 4 && xhttp.status == 200) {
                                document.getElementById("audio_area").innerHTML = xhttp.responseText;
                                $(".media-item").click(function () {
                                    var link = this.getElementsByClassName("media-link")[0].innerHTML;
                                    document.getElementById("library_link").value = link;
                                });
                                $(document).ready(function () {
                                    $('[data-toggle="popover"]').popover();
                                });
                                var max = document.getElementById("load_more_audio").getElementsByClassName("total_media")[0].innerHTML;
                                max++; document.getElementById("load_more_img").getElementsByClassName("total_media")[0].innerHTML = max;
                                max = document.getElementById("load_more_img").getElementsByClassName("total_media")[0].innerHTML;
                                var count = $("#audio_area .media-item").length;
                                if (count < max)
                                    document.getElementById("btn_load_more_audio").style.display = "inline-block";
                            }
                        };
                        sleep(5000);
                        xhttp.open("GET", "../ajax/asp/certificate/load_audio.aspx", true);
                        xhttp.send();
                    }
                }
                else {
                    alert("Bạn chưa đặt tên cho tập tin này");
                }
            }
        }
        else {
            alert("Không có file để Upload");
        }
    });
    $("#btn_upload_video").click(function () {
        var link = document.getElementById("txt_video_link").value;
        var name = document.getElementById("txt_video_name").value;

        if (link == "") {
            alert("Bạn chưa nhập đường dẫn cho video");
        }
        else {
            if (name == "") {
                alert("Bạn chưa đặt tên cho video");
            }
            else {
                document.getElementById("txt_video_link").value = "";
                document.getElementById("txt_video_name").value = "";
                document.getElementById("post-video-modal").style.display = "none";
                document.getElementById("video_area").innerHTML = '<div id="loading"><div id="loading-center-absolute"><div class="object w3-text-teal" id="object_four"></div><div class="object w3-text-teal" id="object_three"></div><div class="object w3-text-teal" id="object_two"></div><div class="object w3-text-teal" id="object_one"></div></div></div>';
                var xhttp;
                xhttp = new XMLHttpRequest();
                xhttp.onreadystatechange = function () {
                    if (xhttp.readyState == 4 && xhttp.status == 200) {
                        document.getElementById("video_area").innerHTML = xhttp.responseText;
                        $(".media-item").click(function () {
                            var link = this.getElementsByClassName("media-link")[0].innerHTML;
                            document.getElementById("library_link").value = link;

                        });
                        $(document).ready(function () {
                            $('[data-toggle="popover"]').popover();
                        });
                        var max = document.getElementById("load_more_video").getElementsByClassName("total_media")[0].innerHTML;
                        max++; document.getElementById("load_more_img").getElementsByClassName("total_media")[0].innerHTML = max;
                        max = document.getElementById("load_more_img").getElementsByClassName("total_media")[0].innerHTML;
                        var count = $("#video_area .media-item").length;
                        if (count < max)
                            document.getElementById("btn_load_more_video").style.display = "inline-block";
                    }
                };
                xhttp.open("GET", "../ajax/asp/certificate/load_video.aspx?name=" + name + "&link=" + link, true);
                xhttp.send();
            }
        }

    });
    $("#btn_load_more_img").click(function () {
        var count = $("#pic_area .media-item").length;
        var max = this.parentElement.getElementsByClassName("total_media")[0].innerHTML;
        var xhttp;
        xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
            if (xhttp.readyState == 4 && xhttp.status == 200) {
                document.getElementById("pic_area").innerHTML += xhttp.responseText;
                $(".media-item").click(function () {
                    var link = this.getElementsByClassName("media-link")[0].innerHTML;
                    document.getElementById("library_link").value = link;
                });
                $(document).ready(function () {
                    $('[data-toggle="popover"]').popover();
                });
                var count_later = $("#pic_area .media-item").length;
                if (max == count_later)
                    document.getElementById("btn_load_more_img").style.display = "none";
            }
        };
        xhttp.open("GET", "../ajax/asp/certificate/load_more_img.aspx?count=" + count, true);
        xhttp.send();
    });

    $("#btn_load_more_audio").click(function () {
        var count = $("#audio_area .media-item").length;
        var max = this.parentElement.getElementsByClassName("total_media")[0].innerHTML;
        var xhttp;
        xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
            if (xhttp.readyState == 4 && xhttp.status == 200) {
                document.getElementById("audio_area").innerHTML += xhttp.responseText;
                $(".media-item").click(function () {
                    var link = this.getElementsByClassName("media-link")[0].innerHTML;
                    document.getElementById("library_link").value = link;
                });
                $(document).ready(function () {
                    $('[data-toggle="popover"]').popover();
                });
                var count_later = $("#audio_area .media-item").length;
                if (max == count_later)
                    document.getElementById("btn_load_more_audio").style.display = "none";
            }
        };
        xhttp.open("GET", "../ajax/asp/certificate/load_more_audio.aspx?count=" + count, true);
        xhttp.send();
    });

    $("#btn_load_more_video").click(function () {
        var count = $("#video_area .media-item").length;
        var max = this.parentElement.getElementsByClassName("total_media")[0].innerHTML;
        var xhttp;
        xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
            if (xhttp.readyState == 4 && xhttp.status == 200) {
                document.getElementById("video_area").innerHTML += xhttp.responseText;
                $(".media-item").click(function () {
                    var link = this.getElementsByClassName("media-link")[0].innerHTML;
                    document.getElementById("library_link").value = link;
                });
                $(document).ready(function () {
                    $('[data-toggle="popover"]').popover();
                });
                var count_later = $("#video_area .media-item").length;
                if (max == count_later)
                    document.getElementById("btn_load_more_video").style.display = "none";
            }
        };
        xhttp.open("GET", "../ajax/asp/certificate/load_more_video.aspx?count=" + count, true);
        xhttp.send();
    });
    $("#word-sound").change(function () {
        readURL3(this);
    });
    $("#fileUpload").change(function () {
        readURL2(this);
    });
    $(".media-item").click(function () {
        var link = this.getElementsByClassName("media-link")[0].innerHTML;
        document.getElementById("library_link").value = link;
    });

    $(".thembaigiang").click(function () {
        document.getElementById('thembaigiang').style.display = 'block';
    });
    $(".btn_add_read").click(function () {
        document.getElementById('themmoidoc').style.display = 'block';
    });
    $(".btn_del_read").click(function () {
        document.getElementById('xoaluyendoc').style.display = 'block';
    });

    $("#btn_del_grammar_example").click(function () {
        var id = document.getElementById("del_example_id").innerHTML;
        var xhttp;
        xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
            if (xhttp.readyState == 4 && xhttp.status == 200) {
                $(".examp" + id).remove();
                document.getElementById("del_grammar_examle").style.display = "none";
            }
        };
        xhttp.open("GET", "../ajax/asp/Lesson/del_grammar_example.aspx?id=" + id, true);
        xhttp.send();
    });
    $("#btn_del_read_content").click(function () {
        var id = document.getElementById("del_read_content_id").innerHTML;
        var xhttp;
        xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
            if (xhttp.readyState == 4 && xhttp.status == 200) {
                $(".read_content_" + id).remove();
                document.getElementById("del_Read_Content").style.display = "none";
            }
        };
        xhttp.open("GET", "../ajax/asp/Lesson/del_read_content.aspx?id=" + id, true);
        xhttp.send();
    });
    $("#btn_del_grammar").click(function () {
        var id = document.getElementById("del_grammar_id").innerHTML;
        var xhttp;
        xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
            if (xhttp.readyState == 4 && xhttp.status == 200) {
                $("#grammar" + id).remove();
                document.getElementById("xoanguphap").style.display = "none";
            }
        };
        xhttp.open("GET", "../ajax/asp/Lesson/del_grammar.aspx?id=" + id, true);
        xhttp.send();
    });
    $("#btn_del_talking").click(function () {
        var id = document.getElementById("del_talk_id").innerHTML;
        $("#talk_ct_" + id).remove();
        document.getElementById("xoahoithoai").style.display = "none";
        $.post("../ajax/asp/lesson/del_talking.aspx", { "id": id });
    });
    $("#btn_del_listening").click(function () {
        var id = document.getElementById("del_listen_id").innerHTML;
        $(".Listen" + id).remove();
        $("#listen" + id).remove();
        document.getElementById("xoaluyennghe").style.display = "none";
        $.post("../ajax/asp/lesson/del_listening.aspx", { "id": id });
    });
    $("#btn_del_exam").click(function () {
        var id = document.getElementById("del_Exam_id").innerHTML;
        $(".exam" + id).remove();
        $("#exam" + id).remove();
        document.getElementById("delete_Exam").style.display = "none";
        $.post("../ajax/asp/lesson/del_Exam.aspx", { "id": id });
    });
    $("#btn_accept_del_read").click(function () {
        var id = document.getElementById("del_read_id").innerHTML;
        $.post("../ajax/asp/lesson/del_Reading.aspx", { 'id': id });
        $("#Read" + id).remove();
        document.getElementById("xoaluyendoc").style.display = "none";
    });
    $("#btn_del_talk_content").click(function () {
        var id = document.getElementById("del_talk_content_id").innerHTML;
        $(".talk_content_" + id).remove();
        $.post("../ajax/asp/lesson/del_talk_content.aspx", { "id": id });
        document.getElementById("del_talk_content").style.display = "none";
    });
    $("#btn_accept_edit_example").click(function () {
        var id = document.getElementById("grammar_example_id").innerHTML;
        var content = document.getElementById("txt_edit_content").value;
        var mean = document.getElementById("txt_edit_mean").value;
        var stt = document.getElementById("grammar_example_count").innerHTML;
        if (content.trim() == "")
            document.getElementById("error_edit_grammar").innerHTML = "Ví dụ không được để trống!";
        else
            if (mean.trim() == "")
                document.getElementById("error_edit_grammar").innerHTML = "VietSub không được để trống!";
            else {
                document.getElementById("error_edit_grammar").innerHTML = "";
                var xhttp;
                xhttp = new XMLHttpRequest();
                xhttp.onreadystatechange = function () {
                    if (xhttp.readyState == 4 && xhttp.status == 200) {
                        document.getElementsByClassName("examp" + id)[0].innerHTML = xhttp.responseText;
                        document.getElementById("edit_grammar_example").style.display = "none";
                        $(".xoavidu-btn").click(function () {
                            var id = this.parentElement.getElementsByClassName("examp_id")[0].innerHTML;
                            document.getElementById("del_example_id").innerHTML = id;
                            document.getElementById("del_grammar_examle").style.display = "block";
                        });
                        $(".suavidu-btn").click(function () {
                            document.getElementById("edit_grammar_example").style.display = "block";
                            var id = this.parentElement.getElementsByClassName("examp_id")[0].innerHTML;
                            document.getElementById("grammar_example_count").innerHTML = this.parentElement.getElementsByClassName("number_grammar_example")[0].innerHTML;
                            document.getElementById("grammar_example_id").innerHTML = id;
                            document.getElementById("txt_edit_content").value = this.parentElement.getElementsByClassName("examp_content")[0].innerHTML;
                            document.getElementById("txt_edit_mean").value = this.parentElement.getElementsByClassName("examp_mean")[0].innerHTML;
                        });
                    }
                };
                xhttp.open("GET", "../ajax/asp/Lesson/edit_grammar_example.aspx?id=" + id + "&content=" + content.trim() + "&mean=" + mean.trim() + "&stt=" + stt, true);
                xhttp.send();
            }
    });
    $("#btn_accept_edit_read_content").click(function () {
        var id = document.getElementById("read_content_id").innerHTML;
        var content = document.getElementById("txt_read_content_edit").value;
        var mean = document.getElementById("txt_read_vietsub_edit").value;
        var stt = document.getElementById("read_content_count").innerHTML;
        if (content.trim() == "")
            document.getElementById("error_Edit_Read").innerHTML = "Nội dung không được để trống!";
        else
            if (mean.trim() == "")
                document.getElementById("error_Edit_Read").innerHTML = "VietSub không được để trống!";
            else {
                document.getElementById("error_Edit_Read").innerHTML = "";
                var xhttp;
                xhttp = new XMLHttpRequest();
                xhttp.onreadystatechange = function () {
                    if (xhttp.readyState == 4 && xhttp.status == 200) {
                        document.getElementsByClassName("read_content_" + id)[0].innerHTML = xhttp.responseText;
                        document.getElementById("edit_read_content").style.display = "none";
                        $(".suavidu-read-btn").click(function () {
                            document.getElementById("edit_read_content").style.display = "block";
                            var id = this.parentElement.getElementsByClassName("read_id")[0].innerHTML;
                            document.getElementById("read_content_count").innerHTML = this.parentElement.getElementsByClassName("number_read_content")[0].innerHTML;
                            document.getElementById("read_content_id").innerHTML = id;
                            document.getElementById("txt_read_content_edit").value = this.parentElement.getElementsByClassName("read_content")[0].innerHTML;
                            document.getElementById("txt_read_vietsub_edit").value = this.parentElement.getElementsByClassName("read_content_mean")[0].innerHTML;
                        });
                        $(".xoavidu-read-btn").click(function () {
                            var id = this.parentElement.getElementsByClassName("read_id")[0].innerHTML;
                            document.getElementById("del_read_content_id").innerHTML = id;
                            document.getElementById("del_Read_Content").style.display = "block";
                        });
                    }
                };
                xhttp.open("GET", "../ajax/asp/Lesson/edit_read_content.aspx?id=" + id + "&content=" + content.trim() + "&mean=" + mean.trim() + "&stt=" + stt, true);
                xhttp.send();
            }
    });
    $("#btn_accept_edit_talk_content").click(function () {
        var id = document.getElementById("edit_talk_content_id").innerHTML;

        var people = document.getElementById("txt_edit_talk_people").value;
        var content = document.getElementById("txt_edit_talk_content").value;
        var sub = document.getElementById("txt_edit_talk_sub").value;

        var xhttp;
        xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
            if (xhttp.readyState == 4 && xhttp.status == 200) {
                document.getElementsByClassName("talk_content_" + id)[0].innerHTML = xhttp.responseText;
                $(document).ready(function () {
                    $('[data-toggle="popover"]').popover();
                });
                $(".suavidu-talk-btn").click(function () {
                    var id = this.parentElement.getElementsByClassName("talk_content_id")[0].innerHTML;
                    document.getElementById("edit_talk_content_id").innerHTML = id;
                    document.getElementById("txt_edit_talk_people").value = this.parentElement.getElementsByClassName("talk_people")[0].innerHTML;
                    document.getElementById("txt_edit_talk_content").value = this.parentElement.getElementsByClassName("talk_content")[0].innerHTML;
                    document.getElementById("txt_edit_talk_sub").value = this.parentElement.getElementsByClassName("talk_sub")[0].innerHTML;
                    document.getElementById("edit_talk_content").style.display = "block";
                });
            }
        };
        xhttp.open("GET", "../ajax/asp/lesson/edit_talk_content.aspx?id=" + id + "&people=" + people + "&content=" + content + "&sub=" + sub, true);
        xhttp.send();
        document.getElementById("edit_talk_content").style.display = "none";
    });
    $("#btn_rename_Listening").click(function () {
        var id = document.getElementById("rename_Listening_id").innerHTML;
        var name = document.getElementById("txt_rename_Listening").value;
        document.getElementById("rename_Listening").style.display = "none";
        $.post("../ajax/asp/lesson/rename_Listening.aspx", { "id": id, 'name': name.trim() });
        //document.getElementsByClassName("Listen" + id)[0].getElementsByClassName("listenlink")
        document.getElementsByClassName("Listen" + id)[0].getElementsByClassName("listen_name")[0].innerHTML = name.trim();
        document.getElementsByClassName("Listen" + id)[0].getElementsByClassName("listenlink")[0].innerHTML = name.trim() + "&nbsp;<i onclick='deletelisten(" + id.trim() + ")' title='Xóa' class='fa fa-times w3-hover-white'></i>"
    });
    $("#btn_rename_talking").click(function () {
        var id = document.getElementById("rename_talking_id").innerHTML;
        var name = document.getElementById("txt_rename_talking").value;
        document.getElementById("rename_talking").style.display = "none";
        $.post("../ajax/asp/lesson/rename_Talking.aspx", { "id": id, 'name': name.trim() });
        document.getElementsByClassName("Talk" + id)[0].getElementsByClassName("talk_name")[0].innerHTML = name.trim();
        document.getElementsByClassName("Talk" + id)[0].getElementsByClassName("converlink")[0].innerHTML = name.trim() + "&nbsp;<i onclick='deleteconver(" + id + ")' title='Xóa' class='fa fa-times w3-hover-white'></i>"
    });
    $("#btn_rename_Exam").click(function () {
        var id = document.getElementById("rename_Exam_id").innerHTML;
        var name = document.getElementById("txt_rename_exam").value;
        document.getElementById("rename_Exam").style.display = "none";
        $.post("../ajax/asp/lesson/rename_Exam.aspx", { "id": id, 'name': name.trim() });
        //document.getElementsByClassName("Listen" + id)[0].getElementsByClassName("listenlink")
        document.getElementsByClassName("exam" + id)[0].getElementsByClassName("exam_name")[0].innerHTML = name.trim();
        document.getElementsByClassName("exam" + id)[0].getElementsByClassName("examlink")[0].innerHTML = name.trim() + "&nbsp;<i onclick='deleteExam(" + id.trim() + ")' title='Xóa' class='fa fa-times w3-hover-white'></i>"
    });
    //Lesson
    $(".choose-lesson-plan").on("change", function () {
        var i, x, tablinks;
        x = document.getElementsByClassName("partoflesson");
        for (i = 0; i < x.length; i++) {
            x[i].style.display = "none";
        }
        tablinks = document.getElementsByClassName("lessonlink");
        for (i = 0; i < x.length; i++) {
            tablinks[i].className = tablinks[i].className.replace(" w3-leftbar w3-border-teal w3-text-teal", "");
        }

        document.getElementById("lesson-part-detail").style.display = "none";

        if (document.getElementsByClassName("choose-lesson-plan")[0].value != 0) {
            document.getElementById("lesson_content").style.display = "block";
            document.getElementById("edit_lesson").style.display = "inline-block";
        }
        else {
            document.getElementById("edit_lesson").style.display = "none";
            document.getElementById("lesson_name").innerHTML = "";
            document.getElementById("lesson_content").style.display = "none";
        }
    });
    $("#btn_new_lesson").click(function () {
        var name = document.getElementById("txt_add_lesson").value;
        var quyen_length = document.getElementsByClassName("quyen").length;
        var quyen = "";
        for (var i = 0; i < quyen_length; i++) {
            if (document.getElementsByClassName("quyen")[i].checked) {
                if (i > 0 && quyen != "")
                    quyen += ",";
                quyen += document.getElementsByClassName("quyen")[i].value;
            }
        }

        var active = "1";
        if ($(".add_lesson .on").hasClass("off"))
            active = "0";
        var xhttp;
        xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
            if (xhttp.readyState == 4 && xhttp.status == 200) {
                location.reload(true);
            }
        };
        xhttp.open("GET", "../ajax/asp/Lesson/add_new_lesson.aspx?name=" + name + "&role=" + quyen + "&active=" + active, true);
        xhttp.send();
    });
    $("#edit_lesson").click(function () {
        document.getElementById("chinhsuabai").style.display = "block";
        var id = document.getElementsByClassName("choose-lesson-plan")[0].value;
        var xhttp;
        xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
            if (xhttp.readyState == 4 && xhttp.status == 200) {
                document.getElementById("edit_lesson_area").innerHTML = xhttp.responseText;
                $(".btn_edit_lesson").click(function () {
                    var id = document.getElementById("edit_lesson_id").innerHTML;
                    var name = document.getElementById("txt_edit_lesson").value.trim();

                    var edit_quyen_length = document.getElementsByClassName("edit_quyen").length;
                    var edit_quyen = "";
                    for (var i = 0; i < edit_quyen_length; i++) {
                        if (document.getElementsByClassName("edit_quyen")[i].checked) {
                            if (i > 0 && edit_quyen != "")
                                edit_quyen += ",";
                            edit_quyen += document.getElementsByClassName("edit_quyen")[i].value;
                        }
                    }

                    var active = "1";
                    if ($(".edit_active .on").hasClass("off"))
                        active = "0";

                    var xhttp;
                    xhttp = new XMLHttpRequest();
                    xhttp.onreadystatechange = function () {
                        if (xhttp.readyState == 4 && xhttp.status == 200) {
                            location.reload(true);
                        }
                    };
                    xhttp.open("GET", "../ajax/asp/Lesson/edit_lesson.aspx?name=" + name + "&id=" + id + "&role=" + edit_quyen + "&active=" + active, true);
                    xhttp.send();
                });
                $(".btn_del_lesson").click(function () {
                    document.getElementById("xoabai").style.display = 'block';
                });
                $(".on").click(function () {
                    if ($(this).hasClass("off")) {
                        $(this).removeClass("off");
                        $(this).removeClass("fa-rotate-180");
                        $(this).removeClass("w3-text-red");
                        $(this).addClass("w3-text-white");
                    }
                    else {
                        $(this).addClass("w3-text-red");
                        $(this).removeClass("w3-text-white");
                        $(this).addClass("fa-rotate-180");
                        $(this).addClass("off");
                    }

                });
            }
        };
        xhttp.open("GET", "../ajax/asp/Lesson/edit_lesson_form.aspx?id=" + id, true);
        xhttp.send();
    });


    $(".btn_deleted_lesson").click(function () {
        var id = document.getElementsByClassName("choose-lesson-plan")[0].value;
        var xhttp;
        xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
            if (xhttp.readyState == 4 && xhttp.status == 200) {
                location.reload(true);
            }
        };
        xhttp.open("GET", "../ajax/asp/Lesson/del_lesson.aspx?id=" + id, true);
        xhttp.send();
    });

    //Word
    $(".btn_add_word").click(function () {
        document.getElementById("word_space").innerHTML += "<tr><td><input class='muctu' type='text' placeholder='Nhập mục từ' /></td><td><input class='hantu' type='text' placeholder='Nhập Hán tự' /></td><td><input class='amhan' type='text' placeholder='Nhập âm Hán' /></td><td><input class='nghia' type='text' placeholder='Nhập ý nghĩa' /></td><td><input class='loaitu' type='text' placeholder='Nhập đường dẫn' /></td><td><a class='w3-btn w3-blue btn_new_word'><i class='fa fa-save'></i>&nbsp;Lưu</a></td></tr>"
        $(".btn_new_word").click(function () {
            var id = document.getElementsByClassName("choose-lesson-plan")[0].value;
            var muctu = this.parentElement.parentElement.getElementsByClassName("muctu")[0].value;
            var loaitu = this.parentElement.parentElement.getElementsByClassName("loaitu")[0].value;
            var hantu = this.parentElement.parentElement.getElementsByClassName("hantu")[0].value;
            var amhan = this.parentElement.parentElement.getElementsByClassName("amhan")[0].value;
            var nghia = this.parentElement.parentElement.getElementsByClassName("nghia")[0].value;
            if (muctu.trim() == "" && loaitu.trim() == "" && hantu.trim() == "" && amhan.trim() == "" && nghia.trim() == "") {
                alert("Nội dung không được để trống");
            }
            else {
                var xhttp;
                xhttp = new XMLHttpRequest();
                xhttp.onreadystatechange = function () {
                    if (xhttp.readyState == 4 && xhttp.status == 200) {
                    }
                };
                xhttp.open("GET", "../ajax/asp/Lesson/add_new_word.aspx?id=" + id + "&muctu=" + muctu + "&loaitu=" + loaitu + "&hantu=" + hantu + "&amhan=" + amhan + "&nghia=" + nghia, true);
                xhttp.send();
                var x = this.parentElement.parentElement.getElementsByTagName("td");
                x[0].innerHTML = muctu;
                x[1].innerHTML = hantu;
                x[2].innerHTML = amhan;
                x[3].innerHTML = nghia;
                if (loaitu == "") {
                    x[4].innerHTML = "<i title='không có file nghe' class='fa fa-volume-up word-speak-btn w3-grey'></i>";
                } else {
                    x[4].classList.add("word-speak-item");
                    x[4].innerHTML = "<span class='word-speak-link w3-hide'>" + loaitu + "</span><i onclick='speak_one(this),pause_speak_all(this)' title='Nghe cách phát âm' class='fa fa-volume-up word-speak-btn w3-btn w3-blue w3-hover-white w3-hover-text-blue'></i>&nbsp;<i onclick='speak_all()' title='Dừng nghe tất cả' class='fa fa-play word-speak-all-btn inline-speak-all-btn w3-btn w3-blue w3-hover-white w3-hover-text-blue'></i>";
                }
                x[5].innerHTML = "<i class='fa fa-check w3-text-blue'></i>"
            }


        });
        $(".word_content").on("dblclick", function () {
            if (!$(this).children().hasClass("muctu") && !$(this).children().hasClass("loaitu") && !$(this).children().hasClass("hantu") && !$(this).children().hasClass("amhan") && !$(this).children().hasClass("nghia")) {
                var x = this.parentElement.getElementsByTagName("td");
                var id = x[0].innerHTML;
                var muctu = x[1].innerHTML;
                var hantu = x[2].innerHTML;
                var amhan = x[3].innerHTML;
                var nghia = x[4].innerHTML;
                var loaitu = x[5].getElementsByClassName("word-speak-link")[0].innerHTML;

                //alert(muctu + " " + loaitu + " " + hantu + " " + amhan + " " + nghia);
                x[1].innerHTML = "<input type='text' class='muctu' value='" + muctu + "' />";
                x[2].innerHTML = "<input type='text' class='hantu' value='" + hantu + "' />";
                x[3].innerHTML = "<input type='text' class='amhan' value='" + amhan + "' />";
                x[4].innerHTML = "<input type='text' class='nghia' value='" + nghia + "' />";
                x[5].innerHTML = "<input type='text' class='loaitu' value='" + loaitu + "' />";
                x[6].innerHTML = "<a class='w3-btn w3-blue btn_edit_word'><i class='fa fa-save'></i>&nbsp;Sửa</a>"
                $(".btn_edit_word").click(function () {
                    var edit_muctu = this.parentElement.parentElement.getElementsByClassName("muctu")[0].value;
                    var edit_loaitu = this.parentElement.parentElement.getElementsByClassName("loaitu")[0].value;
                    var edit_hantu = this.parentElement.parentElement.getElementsByClassName("hantu")[0].value;
                    var edit_amhan = this.parentElement.parentElement.getElementsByClassName("amhan")[0].value;
                    var edit_nghia = this.parentElement.parentElement.getElementsByClassName("nghia")[0].value;
                    //alert(edit_muctu + " " + edit_loaitu + " " + edit_hantu + " " + edit_amhan + " " + edit_nghia);
                    var edit_word;
                    edit_word = new XMLHttpRequest();
                    edit_word.onreadystatechange = function () {
                        if (edit_word.readyState == 4 && edit_word.status == 200) {
                        }
                    };
                    edit_word.open("GET", "../ajax/asp/Lesson/edit_word.aspx?id=" + id + "&muctu=" + edit_muctu + "&loaitu=" + edit_loaitu + "&hantu=" + edit_hantu + "&amhan=" + edit_amhan + "&nghia=" + edit_nghia, true);
                    edit_word.send();
                    var x = this.parentElement.parentElement.getElementsByTagName("td");
                    x[1].innerHTML = edit_muctu;
                    x[2].innerHTML = edit_hantu;
                    x[3].innerHTML = edit_amhan;
                    x[4].innerHTML = edit_nghia;
                    if (edit_loaitu == "") {
                        x[5].innerHTML = "<i title='không có file nghe' class='fa fa-volume-up word-speak-btn w3-grey'></i>";

                    } else {
                        x[5].classList.add("word-speak-item");
                        x[5].innerHTML = "<span class='word-speak-link w3-hide'>" + edit_loaitu + "</span><i onclick='speak_one(this),pause_speak_all(this)' title='Nghe cách phát âm' class='fa fa-volume-up word-speak-btn w3-btn w3-blue w3-hover-white w3-hover-text-blue'></i>&nbsp;<i onclick='speak_all()' title='Dừng nghe tất cả' class='fa fa-play word-speak-all-btn inline-speak-all-btn w3-btn w3-blue w3-hover-white w3-hover-text-blue'></i>";
                    }
                    x[6].innerHTML = "<i class='fa fa-check w3-text-blue'></i>"
                });
            }
        });
    });

    //$("#btn_upload_snd_word").click(function () {
    //    var id = document.getElementsByClassName("choose-lesson-plan")[0].value;
    //    var file = document.getElementById("word-sound").value;
    //    if (file != "") {
    //        var file_data = document.getElementById('word-sound').files[0];
    //        if (file_data == null) return; // chưa chọn file
    //        var form_data = new FormData();
    //        form_data.append("snd_word", file_data);
    //        $.ajax({
    //            url: '../ajax/asp/Lesson/upload_snd_Word.aspx?id=' + id,
    //            data: form_data,
    //            processData: false,
    //            contentType: false,
    //            type: 'POST',
    //            success: function (data) {
    //                //$("#divTreeView").html(data);
    //            }
    //        });
    //        sleep(5000);
    //        document.getElementById("success-modal").style.display = "block";
    //        setTimeout("$('#success-modal').fadeOut()", 2000);
    //    }
    //    else
    //        alert("Tập tin rỗng hoặc không đúng định dạng");
    //});
    $(".btn_del_word").click(function () {
        var lenght = document.getElementsByClassName("word_row").length;
        var del = "";
        var id = 0;
        for (var i = 0; i < lenght; i++) {
            id = document.getElementsByClassName("word_row")[i].getElementsByClassName("word_id")[0].innerHTML;
            if ($("#word" + id).is(":checked")) {
                del += id + ",";
            }
        }

        var xhttp;
        xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
            if (xhttp.readyState == 4 && xhttp.status == 200) {
                var split = del.split(",");
                for (var i = 0; i < split.length; i++) {
                    $("#word_row" + split[i]).remove();
                }
                document.getElementById("xoatuvung").style.display = 'none';
            }
        };
        xhttp.open("GET", "../ajax/asp/Lesson/del_word.aspx?del=" + del, true);
        xhttp.send();
    });

    //Grammar
    $("#btn_new_grammar").click(function () {
        var id = document.getElementsByClassName("choose-lesson-plan")[0].value;
        var name = document.getElementById("txt_new_grammar").value;
        var xhttp;
        xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
            if (xhttp.readyState == 4 && xhttp.status == 200) {
                document.getElementById("grammar").innerHTML += xhttp.responseText;
                document.getElementById("themnguphap").style.display = "none";
                $(".grammar-name").click(function () {
                    if ($(this).parent().hasClass("selected")) {
                        $(this).children(".muiten").removeClass("fa-rotate-180");
                        $(this).parent().children(".lesson-child-content").animate({ height: 'toggle' }, "fast");
                        $(this).parent().removeClass("selected");
                    }
                        //else if ($(this).parent().parent().children().hasClass("selected")) {
                        //    $(this).parent().parent().children(".selected").children(".grammar-name").children(".muiten").removeClass("fa-rotate-180");
                        //    $(this).parent().parent().children(".selected").children(".lesson-child-content").animate({ height: 'toggle' }, "fast");
                        //    $(this).parent().parent().children(".selected").removeClass("selected");
                        //    $(this).parent().addClass("selected");
                        //    $(this).children(".muiten").addClass("fa-rotate-180");
                        //    $(this).parent().children(".lesson-child-content").animate({ height: 'toggle' }, "fast");
                        //}
                    else {
                        $(this).parent().addClass("selected");
                        $(this).children(".muiten").addClass("fa-rotate-180");
                        $(this).parent().children(".lesson-child-content").animate({ height: 'toggle' }, "fast");
                    }
                });
                $(".themvidu-btn").click(function () {
                    $(this).parent().children('.themvidu').animate({ height: 'toggle' }, 'fast')
                });
                $(".btn_edit_grammar").click(function () {
                    var id = this.parentElement.parentElement.parentElement.parentElement.getElementsByClassName("grammar_id")[0].innerHTML;
                    var name = this.parentElement.parentElement.parentElement.parentElement.getElementsByClassName("edit_grammar_name")[0].value;

                    var struc = tinyMCE.get("edit_grammar_structure" + id).getContent();
                    var mean = tinyMCE.get("edit_grammar_mean" + id).getContent();
                    var use = tinyMCE.get("edit_grammar_use" + id).getContent();

                    $.post("../ajax/asp/lesson/edit_grammar.aspx", { 'id': id, 'name': name, 'struc': struc, 'mean': mean, 'use': use });
                    document.getElementById("success-modal").style.display = "block";
                    setTimeout("$('#success-modal').fadeOut()", 2000);
                });
                $(document).ready(function () {
                    $('[data-toggle="popover"]').popover();
                });
                $(".btn_add_grammar_example").click(function () {
                    var id = this.parentElement.parentElement.parentElement.parentElement.parentElement.getElementsByClassName("grammar_id")[0].innerHTML;
                    var content = document.getElementById("grammar" + id).getElementsByClassName("txt_grammar_example")[0].value;
                    var mean = document.getElementById("grammar" + id).getElementsByClassName("txt_grammar_mean")[0].value;

                    var stt = "0";
                    var count = document.getElementById("grammar" + id).getElementsByClassName("number_grammar_example").length;
                    if (count != 0)
                        stt = document.getElementById("grammar" + id).getElementsByClassName("number_grammar_example")[count - 1].innerHTML;
                    var xhttp;
                    xhttp = new XMLHttpRequest();
                    xhttp.onreadystatechange = function () {
                        if (xhttp.readyState == 4 && xhttp.status == 200) {
                            document.getElementById("grammar" + id).getElementsByClassName("example_area")[0].innerHTML += xhttp.responseText;
                            $(".xoavidu-btn").click(function () {
                                var id = this.parentElement.getElementsByClassName("examp_id")[0].innerHTML;
                                document.getElementById("del_example_id").innerHTML = id;
                                document.getElementById("del_grammar_examle").style.display = "block";
                            });
                            $(document).ready(function () {
                                $('[data-toggle="popover"]').popover();
                            });
                            $(".suavidu-btn").click(function () {
                                document.getElementById("edit_grammar_example").style.display = "block";
                                var id = this.parentElement.getElementsByClassName("examp_id")[0].innerHTML;
                                document.getElementById("grammar_example_count").innerHTML = this.parentElement.getElementsByClassName("number_grammar_example")[0].innerHTML;
                                document.getElementById("grammar_example_id").innerHTML = id;
                                document.getElementById("txt_edit_content").value = this.parentElement.getElementsByClassName("examp_content")[0].innerHTML;
                                document.getElementById("txt_edit_mean").value = this.parentElement.getElementsByClassName("examp_mean")[0].innerHTML;
                            });
                        }
                    };
                    xhttp.open("GET", "../ajax/asp/Lesson/add_grammar_example.aspx?id=" + id + "&stt=" + stt + "&content=" + content + "&mean=" + mean, true);
                    xhttp.send();
                });
                $(".xoavidu-btn").click(function () {
                    var id = this.parentElement.getElementsByClassName("examp_id")[0].innerHTML;
                    document.getElementById("del_example_id").innerHTML = id;
                    document.getElementById("del_grammar_examle").style.display = "block";
                });
                $(".suavidu-btn").click(function () {
                    document.getElementById("edit_grammar_example").style.display = "block";
                    var id = this.parentElement.getElementsByClassName("examp_id")[0].innerHTML;
                    document.getElementById("grammar_example_count").innerHTML = this.parentElement.getElementsByClassName("number_grammar_example")[0].innerHTML;
                    document.getElementById("grammar_example_id").innerHTML = id;
                    document.getElementById("txt_edit_content").value = this.parentElement.getElementsByClassName("examp_content")[0].innerHTML;
                    document.getElementById("txt_edit_mean").value = this.parentElement.getElementsByClassName("examp_mean")[0].innerHTML;
                });
                tinymce.remove("textarea");
                tinymce.init({
                    selector: 'textarea',
                    height: 200,
                    width: '100%',
                    plugins: [
                      'advlist autolink lists link image charmap print preview anchor',
                      'searchreplace visualblocks code fullscreen furigana ',
                      'insertdatetime media table contextmenu paste code',
                      'textcolor'
                    ],
                    fontsize_formats: "8px 10px 12px 14px 15px 16px 18px 20px 21px 22px",
                    toolbar: 'fontsizeselect insertfile undo redo | styleselect | bold italic | forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image furigana'
                });
            }
        };
        xhttp.open("GET", "../ajax/asp/Lesson/add_new_grammar.aspx?lesson=" + id + "&name=" + name, true);
        xhttp.send();
    });

    //Reading
    $("#btn_add_reading").click(function () {
        var id = document.getElementsByClassName("choose-lesson-plan")[0].value;
        var name = document.getElementById("read_name").value;
        var xhttp;
        xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
            if (xhttp.readyState == 4 && xhttp.status == 200) {
                document.getElementById("reading").innerHTML += xhttp.responseText;
                document.getElementById('themmoidoc').style.display = 'none';
                $(".reading_file").click(function () {
                    var read_id = this.parentElement.parentElement.parentElement.getElementsByClassName("read_id")[0].innerHTML;
                    $("#reading_file" + read_id).change(function () {
                        readURL(this, read_id);
                    });
                });
                $(".read-name").click(function () {
                    if ($(this).parent().hasClass("selected")) {
                        $(this).children(".muiten").removeClass("fa-rotate-180");
                        $(this).parent().children(".lesson-child-content").animate({ height: 'toggle' }, "fast");
                        $(this).parent().removeClass("selected");
                    }
                        //else if ($(this).parent().parent().children().hasClass("selected")) {
                        //    $(this).parent().parent().children(".selected").children(".read-name").children(".muiten").removeClass("fa-rotate-180");
                        //    $(this).parent().parent().children(".selected").children(".lesson-child-content").animate({ height: 'toggle' }, "fast");
                        //    $(this).parent().parent().children(".selected").removeClass("selected");
                        //    $(this).parent().addClass("selected");
                        //    $(this).children(".muiten").addClass("fa-rotate-180");
                        //    $(this).parent().children(".lesson-child-content").animate({ height: 'toggle' }, "fast");
                        //}
                    else {
                        $(this).parent().addClass("selected");
                        $(this).children(".muiten").addClass("fa-rotate-180");
                        $(this).parent().children(".lesson-child-content").animate({ height: 'toggle' }, "fast");
                    }
                });
                tinymce.remove("textarea");
                tinymce.init({
                    selector: 'textarea',
                    height: 200,
                    width: '100%',
                    plugins: [
                      'advlist autolink lists link image charmap print preview anchor',
                      'searchreplace visualblocks code fullscreen furigana ',
                      'insertdatetime media table contextmenu paste code',
                      'textcolor'
                    ],
                    fontsize_formats: "8px 10px 12px 14px 15px 16px 18px 20px 21px 22px",
                    toolbar: 'fontsizeselect insertfile undo redo | styleselect | bold italic | forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image furigana'
                });
                $(document).ready(function () {
                    $('[data-toggle="popover"]').popover();
                });
                $(".btn_save_reading1").click(function () {
                    var read_id = 0;
                    var temp = this.parentElement.parentElement.parentElement.getElementsByClassName("read_id")[0].innerHTML;
                    if (temp.trim() != "")
                        read_id = temp;
                    //var name = this.parentElement.parentElement.parentElement.getElementsByClassName("txt_read_name")[0].value;
                    //var file = document.getElementById("reading_file" + read_id).value;
                    var read_content = tinyMCE.get("bung-ke").getContent();
                    //name = name.trim();
                    alert(read_id + " " + read_content);
                    //$.post("../ajax/asp/lesson/edit_reading_non-upload.aspx", { 'id': read_id, 'name': name });
                    //document.getElementById("success-modal").style.display = "block";
                    //setTimeout("$('#success-modal').fadeOut()", 2000);
                });
                $(".themnoidung-btn").click(function () {
                    $(this).parent().children('.themvidu').animate({ height: 'toggle' }, 'fast')
                });
                $(".btn_add_read_content").click(function () {
                    var read_id = this.parentElement.parentElement.parentElement.parentElement.parentElement.getElementsByClassName("read_id")[0].innerHTML;
                    var content = this.parentElement.parentElement.getElementsByClassName("txt_reading_content")[0].value;
                    var mean = this.parentElement.parentElement.getElementsByClassName("txt_reading_vietsub")[0].value;

                    var stt = "0";
                    var count = document.getElementById("Read" + read_id).getElementsByClassName("number_read_content").length;
                    if (count != 0)
                        stt = document.getElementById("Read" + read_id).getElementsByClassName("number_read_content")[count - 1].innerHTML;
                    if (content.trim() != "" && content.trim() != "") {
                        var xhttp;
                        xhttp = new XMLHttpRequest();
                        xhttp.onreadystatechange = function () {
                            if (xhttp.readyState == 4 && xhttp.status == 200) {
                                document.getElementById("Read" + read_id).getElementsByClassName("read_content_area")[0].innerHTML += xhttp.responseText;
                                $(document).ready(function () {
                                    $('[data-toggle="popover"]').popover();
                                });
                                $(".suavidu-read-btn").click(function () {
                                    document.getElementById("edit_read_content").style.display = "block";
                                    var id = this.parentElement.getElementsByClassName("read_id")[0].innerHTML;
                                    document.getElementById("read_content_count").innerHTML = this.parentElement.getElementsByClassName("number_read_content")[0].innerHTML;
                                    document.getElementById("read_content_id").innerHTML = id;
                                    document.getElementById("txt_read_content_edit").value = this.parentElement.getElementsByClassName("read_content")[0].innerHTML;
                                    document.getElementById("txt_read_vietsub_edit").value = this.parentElement.getElementsByClassName("read_content_mean")[0].innerHTML;
                                });
                                $(".xoavidu-read-btn").click(function () {
                                    var id = this.parentElement.getElementsByClassName("read_id")[0].innerHTML;
                                    document.getElementById("del_read_content_id").innerHTML = id;
                                    document.getElementById("del_Read_Content").style.display = "block";
                                });
                                this.parentElement.parentElement.getElementsByClassName("txt_reading_content")[0].value = "";
                                this.parentElement.parentElement.getElementsByClassName("txt_reading_vietsub")[0].value = "";
                            }
                        };
                        xhttp.open("GET", "../ajax/asp/Lesson/add_read_content.aspx?id=" + read_id + "&stt=" + stt + "&content=" + content + "&mean=" + mean, true);
                        xhttp.send();
                    }
                    else
                        alert("Nội dung nhập chưa đầy đủ!");
                });
                $(".suavidu-read-btn").click(function () {
                    document.getElementById("edit_read_content").style.display = "block";
                    var id = this.parentElement.getElementsByClassName("read_id")[0].innerHTML;
                    document.getElementById("read_content_count").innerHTML = this.parentElement.getElementsByClassName("number_read_content")[0].innerHTML;
                    document.getElementById("read_content_id").innerHTML = id;
                    document.getElementById("txt_read_content_edit").value = this.parentElement.getElementsByClassName("read_content")[0].innerHTML;
                    document.getElementById("txt_read_vietsub_edit").value = this.parentElement.getElementsByClassName("read_content_mean")[0].innerHTML;
                });
                $(".xoavidu-read-btn").click(function () {
                    var id = this.parentElement.getElementsByClassName("read_id")[0].innerHTML;
                    document.getElementById("del_read_content_id").innerHTML = id;
                    document.getElementById("del_Read_Content").style.display = "block";
                });
                $(".btn_del_reading").click(function () {
                    var read_id = this.parentElement.parentElement.parentElement.getElementsByClassName("read_id")[0].innerHTML;
                    document.getElementById("del_read_id").innerHTML = read_id;
                    document.getElementById("xoaluyendoc").style.display = "block";
                });
            }
        };
        xhttp.open("GET", "../ajax/asp/Lesson/add_new_Reading.aspx?id=" + id + "&name=" + name, true);
        xhttp.send();
    });

    //Listening
    $("#btn_add_listening").click(function () {
        var id = document.getElementsByClassName("choose-lesson-plan")[0].value;
        var name = document.getElementById("txt_add_listening").value;
        var xhttp;
        xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
            if (xhttp.readyState == 4 && xhttp.status == 200) {
                document.getElementById("listen_name_area").innerHTML += xhttp.responseText;
                document.getElementById("themluyennghe").style.display = "none";
                var xhttp1;
                xhttp1 = new XMLHttpRequest();
                xhttp1.onreadystatechange = function () {
                    if (xhttp1.readyState == 4 && xhttp1.status == 200) {
                        document.getElementById("listening").innerHTML += xhttp1.responseText;
                        $(".btn_edit_listening").click(function () {
                            var listen_id = this.parentElement.parentElement.getElementsByClassName("listen_id")[0].innerHTML;

                            var content = tinyMCE.get("listen_content_" + listen_id).getContent();
                            var result = tinyMCE.get("listen_result_" + listen_id).getContent();
                            $.post("../ajax/asp/lesson/edit_listening.aspx", { 'id': listen_id, 'content': content,'result':result });
                            document.getElementById("success-modal").style.display = "block";
                            setTimeout("$('#success-modal').fadeOut()", 2000);

                        });
                        tinymce.remove("textarea");
                        tinymce.init({
                            selector: 'textarea',
                            height: 200,
                            width: '100%',
                            plugins: [
                              'advlist autolink lists link image charmap print preview anchor',
                              'searchreplace visualblocks code fullscreen furigana ',
                              'insertdatetime media table contextmenu paste code',
                              'textcolor'
                            ],
                            fontsize_formats: "8px 10px 12px 14px 15px 16px 18px 20px 21px 22px",
                            toolbar: 'fontsizeselect insertfile undo redo | styleselect | bold italic | forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image furigana'
                        });
                        $(document).ready(function () {
                            $('[data-toggle="popover"]').popover();
                        });

                    }
                };
                xhttp1.open("GET", "../ajax/asp/lesson/add_new_Listening_content.aspx", true);
                xhttp1.send();
            }
        };
        xhttp.open("GET", "../ajax/asp/lesson/add_new_Listening_name.aspx?id=" + id + "&name=" + name);
        xhttp.send();

        
    });
    //Talking
    $("#btn_add_talking").click(function () {
        var id = document.getElementsByClassName("choose-lesson-plan")[0].value;
        var name = document.getElementById("txt_add_talk_name").value;
        var xhttp;
        xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
            if (xhttp.readyState == 4 && xhttp.status == 200) {
                document.getElementById("Talk_little_area").innerHTML += xhttp.responseText;

                document.getElementById("themhoithoai").style.display = "none";
                $(".small-talk-name").click(function () {
                    if ($(this).parent().hasClass("selected")) {
                        $(this).children(".muiten").removeClass("fa-rotate-180");
                        $(this).parent().children(".lesson-child-content").animate({ height: 'toggle' }, "fast");
                        $(this).parent().removeClass("selected");
                    }
                        //else if ($(this).parent().parent().children().hasClass("selected")) {
                        //    $(this).parent().parent().children(".selected").children(".lesson-child-name").children(".muiten").removeClass("fa-rotate-180");
                        //    $(this).parent().parent().children(".selected").children(".lesson-child-content").animate({ height: 'toggle' }, "fast");
                        //    $(this).parent().parent().children(".selected").removeClass("selected");
                        //    $(this).parent().addClass("selected");
                        //    $(this).children(".muiten").addClass("fa-rotate-180");
                        //    $(this).parent().children(".lesson-child-content").animate({ height: 'toggle' }, "fast");
                        //}
                    else {
                        $(this).parent().addClass("selected");
                        $(this).children(".muiten").addClass("fa-rotate-180");
                        $(this).parent().children(".lesson-child-content").animate({ height: 'toggle' }, "fast");
                    }
                });

                $(".btn_edit_talking_cultural").click(function () {
                    alert("aaaa");
                });

                tinymce.remove("textarea");
                tinymce.init({
                    selector: 'textarea',
                    height: 200,
                    width: '100%',
                    plugins: [
                      'advlist autolink lists link image charmap print preview anchor',
                      'searchreplace visualblocks code fullscreen furigana ',
                      'insertdatetime media table contextmenu paste code',
                      'textcolor'
                    ],
                    fontsize_formats: "8px 10px 12px 14px 15px 16px 18px 20px 21px 22px",
                    toolbar: 'fontsizeselect insertfile undo redo | styleselect | bold italic | forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image furigana'
                });

                $(".themdoithoai-btn").click(function () {
                    $(this).parent().children('.themvidu').animate({ height: 'toggle' }, 'fast')
                });
                $(document).ready(function () {
                    $('[data-toggle="popover"]').popover();
                });
                $(".btn_edit_talking").click(function () {
                    var talk_id = this.parentElement.parentElement.getElementsByClassName("talk_id")[0].innerHTML;
                    var content = tinyMCE.get("talk_content").getContent();
                    var result = tinyMCE.get("talk_result_content").getContent();
                    $.post("../ajax/asp/lesson/edit_talking.aspx", { 'id': talk_id, 'content': content, 'result': result });
                    document.getElementById("success-modal").style.display = "block";
                    setTimeout("$('#success-modal').fadeOut()", 2000);
                });

                $(".btn_add_talk_content").click(function () {
                    var talk_id = this.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.getElementsByClassName("talk_id")[0].innerHTML;
                    var people = this.parentElement.parentElement.getElementsByClassName("txt_talk_people")[0].value;
                    var content = this.parentElement.parentElement.getElementsByClassName("txt_talk_content")[0].value;
                    var sub = this.parentElement.parentElement.getElementsByClassName("txt_talk_sub")[0].value;
                    var xhttp;
                    xhttp = new XMLHttpRequest();
                    xhttp.onreadystatechange = function () {
                        if (xhttp.readyState == 4 && xhttp.status == 200) {
                            document.getElementById("Talk" + talk_id).getElementsByClassName("talk_content_area")[0].innerHTML += xhttp.responseText;
                            $(document).ready(function () {
                                $('[data-toggle="popover"]').popover();
                            });
                            $(".themdoithoai-btn").click(function () {
                                $(this).parent().children('.themvidu').animate({ height: 'toggle' }, 'fast')
                            });
                            document.getElementById("Talk" + talk_id).getElementsByClassName("txt_talk_people")[0].value = "";
                            document.getElementById("Talk" + talk_id).getElementsByClassName("txt_talk_content")[0].value = "";
                            document.getElementById("Talk" + talk_id).getElementsByClassName("txt_talk_sub")[0].value = "";
                            $(".suavidu-talk-btn").click(function () {
                                var id = this.parentElement.getElementsByClassName("talk_content_id")[0].innerHTML;
                                document.getElementById("edit_talk_content_id").innerHTML = id;
                                document.getElementById("txt_edit_talk_people").value = this.parentElement.getElementsByClassName("talk_people")[0].innerHTML;
                                document.getElementById("txt_edit_talk_content").value = this.parentElement.getElementsByClassName("talk_content")[0].innerHTML;
                                document.getElementById("txt_edit_talk_sub").value = this.parentElement.getElementsByClassName("talk_sub")[0].innerHTML;
                                document.getElementById("edit_talk_content").style.display = "block";
                            });
                            $(".xoavidu-talk-btn").click(function () {
                                var id = this.parentElement.getElementsByClassName("talk_content_id")[0].innerHTML;
                                document.getElementById("del_talk_content_id").innerHTML = id;
                                document.getElementById("del_talk_content").style.display = "block";
                            });
                        }
                    };
                    xhttp.open("GET", "../ajax/asp/lesson/add_talk_content.aspx?id=" + talk_id + "&people=" + people + "&content=" + content + "&sub=" + sub, true);
                    xhttp.send();
                });
                $(".suavidu-talk-btn").click(function () {
                    var id = this.parentElement.getElementsByClassName("talk_content_id")[0].innerHTML;
                    document.getElementById("edit_talk_content_id").innerHTML = id;
                    document.getElementById("txt_edit_talk_people").value = this.parentElement.getElementsByClassName("talk_people")[0].innerHTML;
                    document.getElementById("txt_edit_talk_content").value = this.parentElement.getElementsByClassName("talk_content")[0].innerHTML;
                    document.getElementById("txt_edit_talk_sub").value = this.parentElement.getElementsByClassName("talk_sub")[0].innerHTML;
                    document.getElementById("edit_talk_content").style.display = "block";
                });
                $(".xoavidu-talk-btn").click(function () {
                    var id = this.parentElement.getElementsByClassName("talk_content_id")[0].innerHTML;
                    document.getElementById("del_talk_content_id").innerHTML = id;
                    document.getElementById("del_talk_content").style.display = "block";
                });
                $(".btn_edit_talking").click(function () {
                    var talk_id = this.parentElement.parentElement.getElementsByClassName("talk_id")[0].innerHTML;
                    var content = tinyMCE.get("talk_content").getContent();
                    var result = tinyMCE.get("talk_result_content").getContent();
                    $.post("../ajax/asp/lesson/edit_talking.aspx", { 'id': talk_id, 'content': content, 'result': result });
                    document.getElementById("success-modal").style.display = "block";
                    setTimeout("$('#success-modal').fadeOut()", 2000);
                });
            }
        };
        xhttp.open("GET", "../ajax/asp/lesson/add_new_Talking_content.aspx?id=" + id + "&name=" + name);
        xhttp.send();
    });
    //Exam
    $("#btn_add_exam").click(function () {
        var id = document.getElementsByClassName("choose-lesson-plan")[0].value;
        var name = document.getElementById("txt_add_exam").value;
        var xhttp;
        xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
            if (xhttp.readyState == 4 && xhttp.status == 200) {
                document.getElementById("exam_name_area").innerHTML += xhttp.responseText;
                document.getElementById("thembaitap").style.display = "none";
                var xhttp1;
                xhttp1 = new XMLHttpRequest();
                xhttp1.onreadystatechange = function () {
                    if (xhttp1.readyState == 4 && xhttp1.status == 200) {
                        document.getElementById("examp").innerHTML += xhttp1.responseText;
                        $(".btn_edit_exam").click(function () {
                            var exam_id = this.parentElement.parentElement.getElementsByClassName("exam_id")[0].innerHTML;

                            var content = tinyMCE.get("exam_content_" + exam_id).getContent();
                            var result = tinyMCE.get("exam_result_" + exam_id).getContent();
                            $.post("../ajax/asp/lesson/edit_Examp.aspx", { 'id': exam_id, 'content': content, 'result': result });
                            document.getElementById("success-modal").style.display = "block";
                            setTimeout("$('#success-modal').fadeOut()", 2000);

                        });
                        tinymce.remove("textarea");
                        tinymce.init({
                            selector: 'textarea',
                            height: 200,
                            width: '100%',
                            plugins: [
                              'advlist autolink lists link image charmap print preview anchor',
                              'searchreplace visualblocks code fullscreen furigana ',
                              'insertdatetime media table contextmenu paste code',
                              'textcolor'
                            ],
                            fontsize_formats: "8px 10px 12px 14px 15px 16px 18px 20px 21px 22px",
                            toolbar: 'fontsizeselect insertfile undo redo | styleselect | bold italic | forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image furigana'
                        });
                        $(document).ready(function () {
                            $('[data-toggle="popover"]').popover();
                        });

                    }
                };
                xhttp1.open("GET", "../ajax/asp/lesson/add_new_exam_content.aspx", true);
                xhttp1.send();
            }
        };
        xhttp.open("GET", "../ajax/asp/lesson/add_new_exam_name.aspx?id=" + id + "&name=" + name);
        xhttp.send();

        
    });
});

function get_word() {
    var audio = document.getElementById("audio_player");
    audio.pause();
    if (audio.classList.contains("speaking-all")) {
        audio.classList.remove("speaking-all");
    }
    var id = document.getElementsByClassName("choose-lesson-plan")[0].value;
    document.getElementById("lesson-part-detail").style.display = "block";
    //từ vựng
    var word;
    word = new XMLHttpRequest();
    word.onreadystatechange = function () {
        if (word.readyState == 4 && word.status == 200) {
            document.getElementById("word").innerHTML = word.responseText;
            $(document).ready(function () {
                $(".word_content").on("dblclick", function () {
                    if (!$(this).children().hasClass("muctu") && !$(this).children().hasClass("loaitu") && !$(this).children().hasClass("hantu") && !$(this).children().hasClass("amhan") && !$(this).children().hasClass("nghia")) {
                        var x = this.parentElement.getElementsByTagName("td");
                        var id = x[0].innerHTML;
                        var muctu = x[1].innerHTML;
                        var hantu = x[2].innerHTML;
                        var amhan = x[3].innerHTML;
                        var nghia = x[4].innerHTML;
                        var loaitu = x[5].getElementsByClassName("word-speak-link")[0].innerHTML;

                        //alert(muctu + " " + loaitu + " " + hantu + " " + amhan + " " + nghia);
                        x[1].innerHTML = "<input type='text' class='muctu' value='" + muctu + "' />";
                        x[2].innerHTML = "<input type='text' class='hantu' value='" + hantu + "' />";
                        x[3].innerHTML = "<input type='text' class='amhan' value='" + amhan + "' />";
                        x[4].innerHTML = "<input type='text' class='nghia' value='" + nghia + "' />";
                        x[5].innerHTML = "<input type='text' class='loaitu' value='" + loaitu + "' />";
                        x[6].innerHTML = "<a class='w3-btn w3-blue btn_edit_word'><i class='fa fa-save'></i>&nbsp;Sửa</a>";
                        $(".btn_edit_word").click(function () {
                            var edit_muctu = this.parentElement.parentElement.getElementsByClassName("muctu")[0].value;
                            var edit_loaitu = this.parentElement.parentElement.getElementsByClassName("loaitu")[0].value;
                            var edit_hantu = this.parentElement.parentElement.getElementsByClassName("hantu")[0].value;
                            var edit_amhan = this.parentElement.parentElement.getElementsByClassName("amhan")[0].value;
                            var edit_nghia = this.parentElement.parentElement.getElementsByClassName("nghia")[0].value;
                            //alert(edit_muctu + " " + edit_loaitu + " " + edit_hantu + " " + edit_amhan + " " + edit_nghia);
                            var edit_word;
                            edit_word = new XMLHttpRequest();
                            edit_word.onreadystatechange = function () {
                                if (edit_word.readyState == 4 && edit_word.status == 200) {
                                }
                            };
                            edit_word.open("GET", "../ajax/asp/Lesson/edit_word.aspx?id=" + id + "&muctu=" + edit_muctu + "&loaitu=" + edit_loaitu + "&hantu=" + edit_hantu + "&amhan=" + edit_amhan + "&nghia=" + edit_nghia, true);
                            edit_word.send();
                            var x = this.parentElement.parentElement.getElementsByTagName("td");
                            x[1].innerHTML = edit_muctu;
                            x[2].innerHTML = edit_hantu;
                            x[3].innerHTML = edit_amhan;
                            x[4].innerHTML = edit_nghia;
                            if (edit_loaitu == "") {
                                x[5].innerHTML = "<i title='không có file nghe' class='fa fa-volume-up word-speak-btn w3-grey'></i>";
                                
                            } else {
                                x[5].classList.add("word-speak-item");
                                x[5].innerHTML = "<span class='word-speak-link w3-hide'>" + edit_loaitu + "</span><i onclick='speak_one(this),pause_speak_all(this)' title='Nghe cách phát âm' class='fa fa-volume-up word-speak-btn w3-btn w3-blue w3-hover-white w3-hover-text-blue'></i>&nbsp;<i onclick='speak_all()' title='Dừng nghe tất cả' class='fa fa-play word-speak-all-btn inline-speak-all-btn w3-btn w3-blue w3-hover-white w3-hover-text-blue'></i>";
                            }
                            x[6].innerHTML = "<i class='fa fa-check w3-text-blue'></i>";
                        });
                    }
                });
                $(function () {
                    $("#sortable").sortable();
                    $("#sortable").disableSelection();
                });
            });
        }
    };
    word.open("GET", "../ajax/asp/Lesson/get_word.aspx?id=" + id, true);
    word.send();

    //var snd_word;
    //snd_word = new XMLHttpRequest();
    //snd_word.onreadystatechange = function () {
    //    if (snd_word.readyState == 4 && snd_word.status == 200) {
    //        document.getElementById("word_sound_area").innerHTML = snd_word.responseText;
    //    }
    //};
    //snd_word.open("GET", "../ajax/asp/Lesson/get_word_snd.aspx?id=" + id, true);
    //snd_word.send();

}

function get_grammar() {
    var id = document.getElementsByClassName("choose-lesson-plan")[0].value;
    document.getElementById("lesson-part-detail").style.display = "block";
    //Ngữ Fap
    var grammar;
    grammar = new XMLHttpRequest();
    grammar.onreadystatechange = function () {
        if (grammar.readyState == 4 && grammar.status == 200) {
            document.getElementById("grammar").innerHTML = grammar.responseText;
            $(".grammar-name").click(function () {
                if ($(this).parent().hasClass("selected")) {
                    $(this).children(".muiten").removeClass("fa-rotate-180");
                    $(this).parent().children(".lesson-child-content").animate({ height: 'toggle' }, "fast");
                    $(this).parent().removeClass("selected");
                }
                    //else if ($(this).parent().parent().children().hasClass("selected")) {
                    //    $(this).parent().parent().children(".selected").children(".grammar-name").children(".muiten").removeClass("fa-rotate-180");
                    //    $(this).parent().parent().children(".selected").children(".lesson-child-content").animate({ height: 'toggle' }, "fast");
                    //    $(this).parent().parent().children(".selected").removeClass("selected");
                    //    $(this).parent().addClass("selected");
                    //    $(this).children(".muiten").addClass("fa-rotate-180");
                    //    $(this).parent().children(".lesson-child-content").animate({ height: 'toggle' }, "fast");
                    //}
                else {
                    $(this).parent().addClass("selected");
                    $(this).children(".muiten").addClass("fa-rotate-180");
                    $(this).parent().children(".lesson-child-content").animate({ height: 'toggle' }, "fast");
                }
            });
            $(".themvidu-btn").click(function () {
                $(this).parent().children('.themvidu').animate({ height: 'toggle' }, 'fast')
            });
            $(".btn_edit_grammar").click(function () {
                var id = this.parentElement.parentElement.parentElement.parentElement.getElementsByClassName("grammar_id")[0].innerHTML;
                var name = this.parentElement.parentElement.parentElement.parentElement.getElementsByClassName("edit_grammar_name")[0].value;

                var struc = tinyMCE.get("edit_grammar_structure" + id).getContent();
                var mean = tinyMCE.get("edit_grammar_mean" + id).getContent();
                var use = tinyMCE.get("edit_grammar_use" + id).getContent();

                $.post("../ajax/asp/lesson/edit_grammar.aspx", { 'id': id, 'name': name, 'struc': struc, 'mean': mean, 'use': use });
                document.getElementById("success-modal").style.display = "block";
                setTimeout("$('#success-modal').fadeOut()", 2000);
            });
            $(document).ready(function () {
                $('[data-toggle="popover"]').popover();
            });
            $(".btn_add_grammar_example").click(function () {
                var id = this.parentElement.parentElement.parentElement.parentElement.parentElement.getElementsByClassName("grammar_id")[0].innerHTML;
                var content = document.getElementById("grammar" + id).getElementsByClassName("txt_grammar_example")[0].value;
                var mean = document.getElementById("grammar" + id).getElementsByClassName("txt_grammar_mean")[0].value;

                var stt = "0";
                var count = document.getElementById("grammar" + id).getElementsByClassName("number_grammar_example").length;
                if (count != 0)
                    stt = document.getElementById("grammar" + id).getElementsByClassName("number_grammar_example")[count - 1].innerHTML;
                if (content.trim() != "" && mean.trim() != "") {
                    var xhttp;
                    xhttp = new XMLHttpRequest();
                    xhttp.onreadystatechange = function () {
                        if (xhttp.readyState == 4 && xhttp.status == 200) {
                            document.getElementById("grammar" + id).getElementsByClassName("example_area")[0].innerHTML += xhttp.responseText;
                            $(".xoavidu-btn").click(function () {
                                var id = this.parentElement.getElementsByClassName("examp_id")[0].innerHTML;
                                document.getElementById("del_example_id").innerHTML = id;
                                document.getElementById("del_grammar_examle").style.display = "block";
                            });
                            $(document).ready(function () {
                                $('[data-toggle="popover"]').popover();
                            });
                            $(".suavidu-btn").click(function () {
                                document.getElementById("edit_grammar_example").style.display = "block";
                                var id = this.parentElement.getElementsByClassName("examp_id")[0].innerHTML;
                                document.getElementById("grammar_example_count").innerHTML = this.parentElement.getElementsByClassName("number_grammar_example")[0].innerHTML;
                                document.getElementById("grammar_example_id").innerHTML = id;
                                document.getElementById("txt_edit_content").value = this.parentElement.getElementsByClassName("examp_content")[0].innerHTML;
                                document.getElementById("txt_edit_mean").value = this.parentElement.getElementsByClassName("examp_mean")[0].innerHTML;
                            });
                            document.getElementById("grammar" + id).getElementsByClassName("txt_grammar_example")[0].value = "";
                            document.getElementById("grammar" + id).getElementsByClassName("txt_grammar_mean")[0].value = "";
                        }
                    };
                    xhttp.open("GET", "../ajax/asp/Lesson/add_grammar_example.aspx?id=" + id + "&stt=" + stt + "&content=" + content.trim() + "&mean=" + mean.trim(), true);
                    xhttp.send();
                }
                else
                    alert("Nội dung ví dụ không đầy đủ!");
            });
            $(".xoavidu-btn").click(function () {
                var id = this.parentElement.getElementsByClassName("examp_id")[0].innerHTML;
                document.getElementById("del_example_id").innerHTML = id;
                document.getElementById("del_grammar_examle").style.display = "block";
            });
            $(".suavidu-btn").click(function () {
                document.getElementById("edit_grammar_example").style.display = "block";
                var id = this.parentElement.getElementsByClassName("examp_id")[0].innerHTML;
                document.getElementById("grammar_example_count").innerHTML = this.parentElement.getElementsByClassName("number_grammar_example")[0].innerHTML;
                document.getElementById("grammar_example_id").innerHTML = id;
                document.getElementById("txt_edit_content").value = this.parentElement.getElementsByClassName("examp_content")[0].innerHTML;
                document.getElementById("txt_edit_mean").value = this.parentElement.getElementsByClassName("examp_mean")[0].innerHTML;
            });
            tinymce.remove("textarea");
            tinymce.init({
                selector: 'textarea',
                height: 200,
                width: '100%',
                plugins: [
                  'advlist autolink lists link image charmap print preview anchor',
                  'searchreplace visualblocks code fullscreen furigana ',
                  'insertdatetime media table contextmenu paste code',
                  'textcolor'
                ],
                fontsize_formats: "8px 10px 12px 14px 15px 16px 18px 20px 21px 22px",
                toolbar: 'fontsizeselect insertfile undo redo | styleselect | bold italic | forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image furigana'
            });
        }
    };
    grammar.open("GET", "../ajax/asp/Lesson/get_grammar.aspx?id=" + id, true);
    grammar.send();
}

function sort_grammar() {
    document.getElementById("sapxepnguphap").style.display = "block";
    var id = document.getElementsByClassName("choose-lesson-plan")[0].value;
    var xhttp;
    xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function () {
        if (xhttp.readyState == 4 && xhttp.status == 200) {
            document.getElementById("sort_grammar").innerHTML = xhttp.responseText;
            $(function () {
                $("#sortable").sortable();
                $("#sortable").disableSelection();
            });
        }
    };
    xhttp.open("GET", "../ajax/asp/Lesson/sort_Grammar.aspx?id=" + id, true);
    xhttp.send();
}

function btn_sort_grammar() {
    var sort = "";
    for (var i = 0; i < document.getElementsByClassName("sort_grammar_id").length; i++) {
        sort += document.getElementsByClassName("sort_grammar_id")[i].innerHTML;
        if (i < document.getElementsByClassName("sort_grammar_id").length-1)
            sort += ",";
    }
    $.post("../Ajax/ASP/Lesson/accept_sort_grammar.aspx", { "area": sort });
    get_grammar();
    document.getElementById("sapxepnguphap").style.display = "none";
}
function get_reading() {
    var id = document.getElementsByClassName("choose-lesson-plan")[0].value;
    document.getElementById("lesson-part-detail").style.display = "block";
    //Luyện Đọc
    var read;
    read = new XMLHttpRequest();
    read.onreadystatechange = function () {
        if (read.readyState == 4 && read.status == 200) {
            document.getElementById("reading").innerHTML = read.responseText;
            $(".reading_file").click(function () {
                var read_id = this.parentElement.parentElement.parentElement.getElementsByClassName("read_id")[0].innerHTML;
                $("#reading_file" + read_id).change(function () {
                    readURL(this, read_id);
                });
            });
            $(".read-name").click(function () {
                if ($(this).parent().hasClass("selected")) {
                    $(this).children(".muiten").removeClass("fa-rotate-180");
                    $(this).parent().children(".lesson-child-content").animate({ height: 'toggle' }, "fast");
                    $(this).parent().removeClass("selected");
                }
                    //else if ($(this).parent().parent().children().hasClass("selected")) {
                    //    $(this).parent().parent().children(".selected").children(".read-name").children(".muiten").removeClass("fa-rotate-180");
                    //    $(this).parent().parent().children(".selected").children(".lesson-child-content").animate({ height: 'toggle' }, "fast");
                    //    $(this).parent().parent().children(".selected").removeClass("selected");
                    //    $(this).parent().addClass("selected");
                    //    $(this).children(".muiten").addClass("fa-rotate-180");
                    //    $(this).parent().children(".lesson-child-content").animate({ height: 'toggle' }, "fast");
                    //}
                else {
                    $(this).parent().addClass("selected");
                    $(this).children(".muiten").addClass("fa-rotate-180");
                    $(this).parent().children(".lesson-child-content").animate({ height: 'toggle' }, "fast");
                }
            });
            tinymce.remove("textarea");
            tinymce.init({
                selector: 'textarea',
                height: 200,
                width: '100%',
                plugins: [
                  'advlist autolink lists link image charmap print preview anchor',
                  'searchreplace visualblocks code fullscreen furigana ',
                  'insertdatetime media table contextmenu paste code',
                  'textcolor'
                ],
                fontsize_formats: "8px 10px 12px 14px 15px 16px 18px 20px 21px 22px",
                toolbar: 'fontsizeselect insertfile undo redo | styleselect | bold italic | forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image furigana'
            });
            $(document).ready(function () {
                $('[data-toggle="popover"]').popover();
            });
            $(".btn_save_reading1").click(function () {
                var lesson_id = document.getElementsByClassName("choose-lesson-plan")[0].value;
                var read_id = 0;
                var temp = this.parentElement.parentElement.parentElement.getElementsByClassName("read_id")[0].innerHTML;
                if (temp.trim() != "")
                    read_id = temp;

                var read_content = tinyMCE.get("bung-ke").getContent();

                $.post("../ajax/asp/lesson/edit_reading_non-upload.aspx", { 'id': read_id, 'content': read_content, 'lesson': lesson_id });
                document.getElementById("success-modal").style.display = "block";
                setTimeout("$('#success-modal').fadeOut()", 2000);
            });
            $(".btn_save_reading2").click(function () {
                var lesson_id = document.getElementsByClassName("choose-lesson-plan")[0].value;
                var read_id = 0;
                var temp = this.parentElement.parentElement.parentElement.getElementsByClassName("read_id")[0].innerHTML;
                if (temp.trim() != "")
                    read_id = temp;

                var read_content = tinyMCE.get("re-bung").getContent();

                $.post("../ajax/asp/lesson/edit_reading_non-upload.aspx", { 'id': read_id, 'content': read_content, 'lesson': lesson_id });
                document.getElementById("success-modal").style.display = "block";
                setTimeout("$('#success-modal').fadeOut()", 2000);
            });
            $(".themnoidung-btn").click(function () {
                $(this).parent().children('.themvidu').animate({ height: 'toggle' }, 'fast')
            });
            $(".btn_add_read_content").click(function () {
                var read_id = this.parentElement.parentElement.parentElement.parentElement.parentElement.getElementsByClassName("read_id")[0].innerHTML;
                var content = this.parentElement.parentElement.getElementsByClassName("txt_reading_content")[0].value;
                var mean = this.parentElement.parentElement.getElementsByClassName("txt_reading_vietsub")[0].value;

                var stt = "0";
                var count = document.getElementById("Read" + read_id).getElementsByClassName("number_read_content").length;
                if (count != 0)
                    stt = document.getElementById("Read" + read_id).getElementsByClassName("number_read_content")[count - 1].innerHTML;
                if (content.trim() != "" && content.trim() != "") {
                    var xhttp;
                    xhttp = new XMLHttpRequest();
                    xhttp.onreadystatechange = function () {
                        if (xhttp.readyState == 4 && xhttp.status == 200) {
                            document.getElementById("Read" + read_id).getElementsByClassName("read_content_area")[0].innerHTML += xhttp.responseText;
                            $(document).ready(function () {
                                $('[data-toggle="popover"]').popover();
                            });
                            $(".suavidu-read-btn").click(function () {
                                document.getElementById("edit_read_content").style.display = "block";
                                var id = this.parentElement.getElementsByClassName("read_id")[0].innerHTML;
                                document.getElementById("read_content_count").innerHTML = this.parentElement.getElementsByClassName("number_read_content")[0].innerHTML;
                                document.getElementById("read_content_id").innerHTML = id;
                                document.getElementById("txt_read_content_edit").value = this.parentElement.getElementsByClassName("read_content")[0].innerHTML;
                                document.getElementById("txt_read_vietsub_edit").value = this.parentElement.getElementsByClassName("read_content_mean")[0].innerHTML;
                            });
                            $(".xoavidu-read-btn").click(function () {
                                var id = this.parentElement.getElementsByClassName("read_id")[0].innerHTML;
                                document.getElementById("del_read_content_id").innerHTML = id;
                                document.getElementById("del_Read_Content").style.display = "block";
                            });
                            this.parentElement.parentElement.getElementsByClassName("txt_reading_content")[0].value = "";
                            this.parentElement.parentElement.getElementsByClassName("txt_reading_vietsub")[0].value = "";
                        }
                    };
                    xhttp.open("GET", "../ajax/asp/Lesson/add_read_content.aspx?id=" + read_id + "&stt=" + stt + "&content=" + content + "&mean=" + mean, true);
                    xhttp.send();
                }
                else
                    alert("Nội dung nhập chưa đầy đủ!");
            });
            $(".suavidu-read-btn").click(function () {
                document.getElementById("edit_read_content").style.display = "block";
                var id = this.parentElement.getElementsByClassName("read_id")[0].innerHTML;
                document.getElementById("read_content_count").innerHTML = this.parentElement.getElementsByClassName("number_read_content")[0].innerHTML;
                document.getElementById("read_content_id").innerHTML = id;
                document.getElementById("txt_read_content_edit").value = this.parentElement.getElementsByClassName("read_content")[0].innerHTML;
                document.getElementById("txt_read_vietsub_edit").value = this.parentElement.getElementsByClassName("read_content_mean")[0].innerHTML;
            });
            $(".xoavidu-read-btn").click(function () {
                var id = this.parentElement.getElementsByClassName("read_id")[0].innerHTML;
                document.getElementById("del_read_content_id").innerHTML = id;
                document.getElementById("del_Read_Content").style.display = "block";
            });
            $(".btn_del_reading").click(function () {
                var read_id = this.parentElement.parentElement.parentElement.getElementsByClassName("read_id")[0].innerHTML;
                document.getElementById("del_read_id").innerHTML = read_id;
                document.getElementById("xoaluyendoc").style.display = "block";
            });
        }
    };
    read.open("GET", "../ajax/asp/Lesson/get_Reading.aspx?id=" + id, true);
    read.send();
};

function get_listening() {
    var id = document.getElementsByClassName("choose-lesson-plan")[0].value;
    document.getElementById("lesson-part-detail").style.display = "block";
    //Luyện Nghe
    var listen;
    listen = new XMLHttpRequest();
    listen.onreadystatechange = function () {
        if (listen.readyState == 4 && listen.status == 200) {
            document.getElementById("listening").innerHTML = listen.responseText;
            $(document).ready(function () {
                $(document).ready(function () {
                    $('[data-toggle="popover"]').popover();
                });
                $(".btn_edit_listening").click(function () {
                    var listen_id = this.parentElement.parentElement.getElementsByClassName("listen_id")[0].innerHTML;
                    var content = tinyMCE.get("listen_content_" + listen_id).getContent();
                    var result = tinyMCE.get("listen_result_" + listen_id).getContent();
                    $.post("../ajax/asp/lesson/edit_listening.aspx", { 'id': listen_id, 'content': content, 'result': result });
                    document.getElementById("success-modal").style.display = "block";
                    setTimeout("$('#success-modal').fadeOut()", 2000);
                });
                tinymce.remove("textarea");
                tinymce.init({
                    selector: 'textarea',
                    height: 200,
                    width: '100%',
                    plugins: [
                      'advlist autolink lists link image charmap print preview anchor',
                      'searchreplace visualblocks code fullscreen furigana ',
                      'insertdatetime media table contextmenu paste code',
                      'textcolor'
                    ],
                    fontsize_formats: "8px 10px 12px 14px 15px 16px 18px 20px 21px 22px",
                    toolbar: 'fontsizeselect insertfile undo redo | styleselect | bold italic | forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image furigana'
                });
            });
        }
    };
    listen.open("GET", "../ajax/asp/Lesson/get_Listening.aspx?id=" + id, true);
    listen.send();
};

function get_talking() {
    var id = document.getElementsByClassName("choose-lesson-plan")[0].value;
    document.getElementById("lesson-part-detail").style.display = "block";
    //Talk
    var talk;
    talk = new XMLHttpRequest();
    talk.onreadystatechange = function () {
        if (talk.readyState == 4 && talk.status == 200) {
            document.getElementById("talking").innerHTML = talk.responseText;
            $(".small-talk-name").click(function () {
                if ($(this).parent().hasClass("selected")) {
                    $(this).children(".muiten").removeClass("fa-rotate-180");
                    $(this).parent().children(".lesson-child-content").animate({ height: 'toggle' }, "fast");
                    $(this).parent().removeClass("selected");
                }
                    //else if ($(this).parent().parent().children().hasClass("selected")) {
                    //    $(this).parent().parent().children(".selected").children(".lesson-child-name").children(".muiten").removeClass("fa-rotate-180");
                    //    $(this).parent().parent().children(".selected").children(".lesson-child-content").animate({ height: 'toggle' }, "fast");
                    //    $(this).parent().parent().children(".selected").removeClass("selected");
                    //    $(this).parent().addClass("selected");
                    //    $(this).children(".muiten").addClass("fa-rotate-180");
                    //    $(this).parent().children(".lesson-child-content").animate({ height: 'toggle' }, "fast");
                    //}
                else {
                    $(this).parent().addClass("selected");
                    $(this).children(".muiten").addClass("fa-rotate-180");
                    $(this).parent().children(".lesson-child-content").animate({ height: 'toggle' }, "fast");
                }
            });

            tinymce.remove("textarea");
            tinymce.init({
                selector: 'textarea',
                height: 200,
                width: '100%',
                plugins: [
                  'advlist autolink lists link image charmap print preview anchor',
                  'searchreplace visualblocks code fullscreen furigana ',
                  'insertdatetime media table contextmenu paste code',
                  'textcolor'
                ],
                fontsize_formats: "8px 10px 12px 14px 15px 16px 18px 20px 21px 22px",
                toolbar: 'fontsizeselect insertfile undo redo | styleselect | bold italic | forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image furigana'
            });
            $(".themdoithoai-btn").click(function () {
                $(this).parent().children('.themvidu').animate({ height: 'toggle' }, 'fast')
            });
            $(document).ready(function () {
                $('[data-toggle="popover"]').popover();
            });
            $(".btn_add_talk_content").click(function () {
                var talk_id = this.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.getElementsByClassName("talk_id")[0].innerHTML;
                var people = this.parentElement.parentElement.getElementsByClassName("txt_talk_people")[0].value;
                var content = this.parentElement.parentElement.getElementsByClassName("txt_talk_content")[0].value;
                var sub = this.parentElement.parentElement.getElementsByClassName("txt_talk_sub")[0].value;
                var xhttp;
                xhttp = new XMLHttpRequest();
                xhttp.onreadystatechange = function () {
                    if (xhttp.readyState == 4 && xhttp.status == 200) {
                        document.getElementById("Talk" + talk_id).getElementsByClassName("talk_content_area")[0].innerHTML += xhttp.responseText;
                        $(document).ready(function () {
                            $('[data-toggle="popover"]').popover();
                        });
                        $(".themdoithoai-btn").click(function () {
                            $(this).parent().children('.themvidu').animate({ height: 'toggle' }, 'fast')
                        });
                        document.getElementById("Talk" + talk_id).getElementsByClassName("txt_talk_people")[0].value = "";
                        document.getElementById("Talk" + talk_id).getElementsByClassName("txt_talk_content")[0].value = "";
                        document.getElementById("Talk" + talk_id).getElementsByClassName("txt_talk_sub")[0].value = "";
                        $(".suavidu-talk-btn").click(function () {
                            var id = this.parentElement.getElementsByClassName("talk_content_id")[0].innerHTML;
                            document.getElementById("edit_talk_content_id").innerHTML = id;
                            document.getElementById("txt_edit_talk_people").value = this.parentElement.getElementsByClassName("talk_people")[0].innerHTML;
                            document.getElementById("txt_edit_talk_content").value = this.parentElement.getElementsByClassName("talk_content")[0].innerHTML;
                            document.getElementById("txt_edit_talk_sub").value = this.parentElement.getElementsByClassName("talk_sub")[0].innerHTML;
                            document.getElementById("edit_talk_content").style.display = "block";
                        });
                        $(".xoavidu-talk-btn").click(function () {
                            var id = this.parentElement.getElementsByClassName("talk_content_id")[0].innerHTML;
                            document.getElementById("del_talk_content_id").innerHTML = id;
                            document.getElementById("del_talk_content").style.display = "block";
                        });
                    }
                };
                xhttp.open("GET", "../ajax/asp/lesson/add_talk_content.aspx?id=" + talk_id + "&people=" + people + "&content=" + content + "&sub=" + sub, true);
                xhttp.send();
            });
            $(".suavidu-talk-btn").click(function () {
                var id = this.parentElement.getElementsByClassName("talk_content_id")[0].innerHTML;
                document.getElementById("edit_talk_content_id").innerHTML = id;
                document.getElementById("txt_edit_talk_people").value = this.parentElement.getElementsByClassName("talk_people")[0].innerHTML;
                document.getElementById("txt_edit_talk_content").value = this.parentElement.getElementsByClassName("talk_content")[0].innerHTML;
                document.getElementById("txt_edit_talk_sub").value = this.parentElement.getElementsByClassName("talk_sub")[0].innerHTML;
                document.getElementById("edit_talk_content").style.display = "block";
            });
            $(".xoavidu-talk-btn").click(function () {
                var id = this.parentElement.getElementsByClassName("talk_content_id")[0].innerHTML;
                document.getElementById("del_talk_content_id").innerHTML = id;
                document.getElementById("del_talk_content").style.display = "block";
            });
            $(".btn_edit_talking").click(function () {
                var talk_id = this.parentElement.parentElement.getElementsByClassName("talk_id")[0].innerHTML;
                var content = tinyMCE.get("talk_content").getContent();
                var result = tinyMCE.get("talk_result_content").getContent();
                $.post("../ajax/asp/lesson/edit_talking.aspx", { 'id': talk_id, 'content': content, 'result': result });
                document.getElementById("success-modal").style.display = "block";
                setTimeout("$('#success-modal').fadeOut()", 2000);
            });

        }
    };
    talk.open("GET", "../ajax/asp/Lesson/get_Talking.aspx?id=" + id, true);
    talk.send();
    $(".themdoithoai-btn").click(function () {
        $(this).parent().children('.themvidu').animate({ height: 'toggle' }, 'fast')
    });
};

function get_examp() {
    var id = document.getElementsByClassName("choose-lesson-plan")[0].value;
    document.getElementById("lesson-part-detail").style.display = "block";

    //Examp
    var examp;
    examp = new XMLHttpRequest();
    examp.onreadystatechange = function () {
        if (examp.readyState == 4 && examp.status == 200) {
            document.getElementById("examp").innerHTML = examp.responseText;

            $(".btn_edit_exam").click(function () {
                var exam_id = this.parentElement.parentElement.getElementsByClassName("exam_id")[0].innerHTML;

                var content = tinyMCE.get("exam_content_" + exam_id).getContent();
                var result = tinyMCE.get("exam_result_" + exam_id).getContent();
                $.post("../ajax/asp/lesson/edit_Examp.aspx", { 'id': exam_id, 'content': content, 'result': result });
                document.getElementById("success-modal").style.display = "block";
                setTimeout("$('#success-modal').fadeOut()", 2000);

            });
            $(".btn_edit_exam").click(function () {
                var exam_id = this.parentElement.parentElement.getElementsByClassName("exam_id")[0].innerHTML;

                var content = tinyMCE.get("exam_content_" + exam_id).getContent();
                var result = tinyMCE.get("exam_result_" + exam_id).getContent();
                $.post("../ajax/asp/lesson/edit_Examp.aspx", { 'id': exam_id, 'content': content, 'result': result });
                document.getElementById("success-modal").style.display = "block";
                setTimeout("$('#success-modal').fadeOut()", 2000);

            });
            tinymce.remove("textarea");
            tinymce.init({
                selector: 'textarea',
                height: 200,
                width: '100%',
                plugins: [
                  'advlist autolink lists link image charmap print preview anchor',
                  'searchreplace visualblocks code fullscreen furigana ',
                  'insertdatetime media table contextmenu paste code',
                  'textcolor'
                ],
                fontsize_formats: "8px 10px 12px 14px 15px 16px 18px 20px 21px 22px",
                toolbar: 'fontsizeselect insertfile undo redo | styleselect | bold italic | forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image furigana'
            });
        }
    };
    examp.open("GET", "../ajax/asp/Lesson/get_examp.aspx?id=" + id, true);
    examp.send();
};

function save_examp() {
    var id = document.getElementsByClassName("choose-lesson-plan")[0].value;
    var examp = tinyMCE.get("lesson_examp").getContent();

    $.post("../ajax/asp/lesson/edit_Examp.aspx", { "id": id, "examp": examp });
    document.getElementById("success-modal").style.display = "block";
    setTimeout("$('#success-modal').fadeOut()", 2000);
};

function edit_talking_cultural(id) {
    $(document).ready(function () {
        var text = tinyMCE.get("talking_cultural").getContent();
        $.post("../ajax/asp/lesson/edit_talking_cultural.aspx", { 'id': id, 'content': text });
        document.getElementById("success-modal").style.display = "block";
        setTimeout("$('#success-modal').fadeOut()", 2000);
    });
}
function saveChangeArea() {
    var id = document.getElementsByClassName("choose-lesson-plan")[0].value;
    var z = "";
    var l = document.getElementById("sortable").getElementsByClassName("ui-state-default").length;
    for (var i = 0; i < l; i++) {
        if (i != 0)
            z += ",";
        z += document.getElementById("sortable").getElementsByClassName("ui-state-default")[i].getElementsByClassName("word_id")[0].innerHTML;
    }
    $.post("../ajax/asp/lesson/change_area.aspx", { 'id': id, 'area': z });
    document.getElementById("success-modal").style.display = "block";
    setTimeout("$('#success-modal').fadeOut()", 2000);
}
function deletevolcabulary() {
    document.getElementById('xoatuvung').style.display = 'block';
}
function openlisten(evt, listenname) {
    var i, x, tablinks;
    x = document.getElementsByClassName("listenpart");
    for (i = 0; i < x.length; i++) {
        x[i].style.display = "none";
    }
    tablinks = document.getElementsByClassName("listenlink");
    for (i = 0; i < x.length; i++) {
        tablinks[i].className = tablinks[i].className.replace(" w3-purple", "");
    }
    document.getElementById(listenname).style.display = "block";
    evt.currentTarget.className += " w3-purple";
}
function openexam(evt, listenname) {
    var i, x, tablinks;
    x = document.getElementsByClassName("exampart");
    for (i = 0; i < x.length; i++) {
        x[i].style.display = "none";
    }
    tablinks = document.getElementsByClassName("examlink");
    for (i = 0; i < x.length; i++) {
        tablinks[i].className = tablinks[i].className.replace(" w3-green", "");
    }
    document.getElementById(listenname).style.display = "block";
    evt.currentTarget.className += " w3-green";
}
function editListen(id) {
    var name = document.getElementsByClassName("Listen" + id)[0].getElementsByClassName("listen_name")[0].innerHTML;
    document.getElementById("rename_Listening").style.display = "block";
    document.getElementById("rename_Listening_id").innerHTML = id;
    document.getElementById("txt_rename_Listening").value = name.trim();
}
function editExam(id) {
    var name = document.getElementsByClassName("exam" + id)[0].getElementsByClassName("exam_name")[0].innerHTML;
    document.getElementById("rename_Exam").style.display = "block";
    document.getElementById("rename_Exam_id").innerHTML = id;
    document.getElementById("txt_rename_exam").value = name.trim();
}
function renameTalk(id) {
    var name = document.getElementsByClassName("Talk" + id)[0].getElementsByClassName("talk_name")[0].innerHTML;
    document.getElementById("rename_talking").style.display = "block";
    document.getElementById("rename_talking_id").innerHTML = id;
    document.getElementById("txt_rename_talking").value = name.trim();
}
function addlisten() {
    document.getElementById("themluyennghe").style.display = "block";
}
function deletelisten(id) {
    document.getElementById("del_listen_id").innerHTML = id;
    document.getElementById("delete_Exam").style.display = "block";
}
function deleteExam(id) {
    document.getElementById("del_Exam_id").innerHTML = id;
    document.getElementById("delete_Exam").style.display = "block";
}
function update_word() {
    var audio = document.getElementById("audio_player");
    audio.pause();
    if (audio.classList.contains("speaking-all")) {
        audio.classList.remove("speaking-all");
    }
    var id = document.getElementsByClassName("choose-lesson-plan")[0].value;
    var word;
    word = new XMLHttpRequest();
    word.onreadystatechange = function () {
        if (word.readyState == 4 && word.status == 200) {
            document.getElementById("word").innerHTML = word.responseText;
            $(document).ready(function () {
                $(".word_content").on("dblclick", function () {
                    if (!$(this).children().hasClass("muctu") && !$(this).children().hasClass("loaitu") && !$(this).children().hasClass("hantu") && !$(this).children().hasClass("amhan") && !$(this).children().hasClass("nghia")) {
                        var x = this.parentElement.getElementsByTagName("td");
                        var id = x[0].innerHTML;
                        var muctu = x[1].innerHTML;
                        var hantu = x[2].innerHTML;
                        var amhan = x[3].innerHTML;
                        var nghia = x[4].innerHTML;
                        var loaitu = x[5].getElementsByClassName("word-speak-link")[0].innerHTML;

                        //alert(muctu + " " + loaitu + " " + hantu + " " + amhan + " " + nghia);
                        x[1].innerHTML = "<input type='text' class='muctu' value='" + muctu + "' />";
                        x[2].innerHTML = "<input type='text' class='hantu' value='" + hantu + "' />";
                        x[3].innerHTML = "<input type='text' class='amhan' value='" + amhan + "' />";
                        x[4].innerHTML = "<input type='text' class='nghia' value='" + nghia + "' />";
                        x[5].innerHTML = "<input type='text' class='loaitu' value='" + loaitu + "' />";
                        x[6].innerHTML = "<a class='w3-btn w3-blue btn_edit_word'><i class='fa fa-save'></i>&nbsp;Sửa</a>"
                        $(".btn_edit_word").click(function () {
                            var edit_muctu = this.parentElement.parentElement.getElementsByClassName("muctu")[0].value;
                            var edit_loaitu = this.parentElement.parentElement.getElementsByClassName("loaitu")[0].value;
                            var edit_hantu = this.parentElement.parentElement.getElementsByClassName("hantu")[0].value;
                            var edit_amhan = this.parentElement.parentElement.getElementsByClassName("amhan")[0].value;
                            var edit_nghia = this.parentElement.parentElement.getElementsByClassName("nghia")[0].value;
                            //alert(edit_muctu + " " + edit_loaitu + " " + edit_hantu + " " + edit_amhan + " " + edit_nghia);
                            var edit_word;
                            edit_word = new XMLHttpRequest();
                            edit_word.onreadystatechange = function () {
                                if (edit_word.readyState == 4 && edit_word.status == 200) {
                                }
                            };
                            edit_word.open("GET", "../ajax/asp/Lesson/edit_word.aspx?id=" + id + "&muctu=" + edit_muctu + "&loaitu=" + edit_loaitu + "&hantu=" + edit_hantu + "&amhan=" + edit_amhan + "&nghia=" + edit_nghia, true);
                            edit_word.send();
                            var x = this.parentElement.parentElement.getElementsByTagName("td");
                            x[1].innerHTML = edit_muctu;
                            x[2].innerHTML = edit_hantu;
                            x[3].innerHTML = edit_amhan;
                            x[4].innerHTML = edit_nghia;
                            if (edit_loaitu == "") {
                                x[5].innerHTML = "<i title='không có file nghe' class='fa fa-volume-up word-speak-btn w3-grey'></i>";

                            } else {
                                x[5].classList.add("word-speak-item");
                                x[5].innerHTML = "<span class='word-speak-link w3-hide'>" + edit_loaitu + "</span><i onclick='speak_one(this),pause_speak_all(this)' title='Nghe cách phát âm' class='fa fa-volume-up word-speak-btn w3-btn w3-blue w3-hover-white w3-hover-text-blue'></i>&nbsp;<i onclick='speak_all()' title='Dừng nghe tất cả' class='fa fa-play word-speak-all-btn inline-speak-all-btn w3-btn w3-blue w3-hover-white w3-hover-text-blue'></i>";
                            }
                            x[6].innerHTML = "<i class='fa fa-check w3-text-blue'></i>"
                        });
                    }
                });
                $(function () {
                    $("#sortable").sortable();
                    $("#sortable").disableSelection();
                });
            });
        }
    };
    word.open("GET", "../ajax/asp/Lesson/get_word.aspx?id=" + id, true);
    word.send();
}
function openconver(evt, convername) {
    var i, x, tablinks;
    x = document.getElementsByClassName("converpart");
    for (i = 0; i < x.length; i++) {
        x[i].style.display = "none";
    }
    tablinks = document.getElementsByClassName("converlink");
    for (i = 0; i < x.length; i++) {
        tablinks[i].className = tablinks[i].className.replace(" w3-red", "");
    }
    document.getElementById(convername).style.display = "block";
    evt.currentTarget.className += " w3-red";
}
function addconver() {
    document.getElementById("themhoithoai").style.display = "block";
}
function deleteconver(id) {
    document.getElementById("xoahoithoai").style.display = "block";
    document.getElementById("del_talk_id").innerHTML = id;
}
function openpartoflesson(evt, partname) {
    var i, x, tablinks;
    x = document.getElementsByClassName("partoflesson");
    for (i = 0; i < x.length; i++) {
        x[i].style.display = "none";
    }
    tablinks = document.getElementsByClassName("lessonlink");
    for (i = 0; i < x.length; i++) {
        tablinks[i].className = tablinks[i].className.replace(" w3-leftbar w3-border-teal w3-text-teal", "");
    }
    document.getElementById(partname).style.display = "block";
    evt.currentTarget.className += " w3-leftbar w3-border-teal w3-text-teal";
}
function hidepartoflesson() {
    var p;
    p = document.getElementsByClassName("partoflesson");
    for (var i = 0; i < p.length; i++) {
        p[i].style.display = "none";
    }
}
function openpartoflesson2(evt, partname) {
    var i, x, y, tablinks;
    x = document.getElementsByClassName("partoflesson");
    y = document.getElementsByClassName("lesson-detail");
    for (i = 0; i < x.length; i++) {
        x[i].style.display = "none";
        y[i].innerHTML = "";
    }
    tablinks = document.getElementsByClassName("lessonlink");
    for (i = 0; i < x.length; i++) {
        tablinks[i].className = tablinks[i].className.replace(" w3-leftbar w3-border-teal w3-text-teal", "");
    }
    document.getElementById(partname).style.display = "block";
    evt.currentTarget.className += " w3-leftbar w3-border-teal w3-text-teal";
}
function hidepartoflesson2() {
    var p;
    p = document.getElementsByClassName("partoflesson");
    for (var i = 0; i < p.length; i++) {
        p[i].style.display = "none";
    }
}
function save_talking_ct(id) {
    var content = tinyMCE.get("talk_CT_Content" + id).getContent();
    var result = tinyMCE.get("talk_CT_Result" + id).getContent();
    var train = tinyMCE.get("talk_CT_Train" + id).getContent();
    var name = document.getElementById("txt_talkct_name" + id).value;
    $.post("../ajax/asp/lesson/edit_talk_content.aspx", { "id": id, "content": content, "result": result, "train": train, "name": name });
    document.getElementById("success-modal").style.display = "block";
    setTimeout("$('#success-modal').fadeOut()", 2000);
}
function del_talking_ct(id) {
    document.getElementById("del_talk_id").innerHTML = id;
    document.getElementById('xoahoithoai').style.display = 'block'

}
function addExam() {
    document.getElementById("thembaitap").style.display = "block";
}
